Skip to content

BaseField class

edgy.core.db.fields.base.BaseField

BaseField(*, default=Undefined, server_default=Undefined, **kwargs)

Bases: BaseFieldType, FieldInfo

The foundational class for all Edgy model fields.

This class extends BaseFieldType and pydantic.fields.FieldInfo to provide core functionalities for defining model attributes, including database column mapping, validation, and default value handling. It also offers mechanisms for dynamic operator mapping for query building.

ATTRIBUTE DESCRIPTION
owner

The model class to which this field belongs.

TYPE: type[BaseModelType]

operator_mapping

A dictionary mapping common operator strings to SQLAlchemy's ColumnElement methods for query construction.

TYPE: dict[str, str]

auto_compute_server_default

Controls the automatic computation of server defaults. Can be True, False, None, or "ignore_null". None means use global settings, "ignore_null" means ignore nullability for auto-computation.

TYPE: bool | None | Literal['ignore_null']

Initializes a new BaseField instance.

This constructor processes default values, server defaults, and other field configurations, integrating them with Pydantic's FieldInfo.

PARAMETER DESCRIPTION
default

The default Python value for the field. If Undefined, no Python default is set.

TYPE: Any DEFAULT: Undefined

server_default

The default value to be set by the database server. If Undefined, no server default is explicitly set.

TYPE: Any DEFAULT: Undefined

**kwargs

Additional keyword arguments to be passed to FieldInfo and stored as attributes of the field.

TYPE: Any DEFAULT: {}

Source code in edgy/core/db/fields/base.py
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
def __init__(
    self,
    *,
    default: Any = Undefined,
    server_default: Any = Undefined,
    **kwargs: Any,
) -> None:
    """
    Initializes a new `BaseField` instance.

    This constructor processes default values, server defaults, and other
    field configurations, integrating them with Pydantic's `FieldInfo`.

    Args:
        default: The default Python value for the field. If `Undefined`,
                 no Python default is set.
        server_default: The default value to be set by the database server.
                        If `Undefined`, no server default is explicitly set.
        **kwargs: Additional keyword arguments to be passed to `FieldInfo`
                  and stored as attributes of the field.
    """
    # If '__type__' is provided in kwargs, rename it to 'field_type'.
    if "__type__" in kwargs:
        kwargs["field_type"] = kwargs.pop("__type__")
    # Determine if 'None' was explicitly provided as a default.
    self.explicit_none = default is None
    # Store the server_default.
    self.server_default = server_default

    # Call the parent FieldInfo constructor with remaining kwargs.
    super().__init__(**kwargs)

    # Set any remaining keyword arguments as attributes of the field instance.
    for name, value in kwargs.items():
        setattr(self, name, value)

    # If the field is nullable, has a server default, or is autoincrementing,
    # and no default was explicitly provided, set the default to None.
    # This ensures backward compatibility and aligns with pydantic_core's
    # handling of nullable columns.
    if (
        self.null
        or (self.server_default is not None and self.server_default is not Undefined)
        or self.autoincrement
    ) and default is Undefined:
        default = None
    # If a default value was determined (either provided or set to None),
    # apply it to the field.
    if default is not Undefined:
        self.default = default

owner instance-attribute

owner

operator_mapping class-attribute instance-attribute

operator_mapping = {'is': 'is_', 'in': 'in_', 'exact': '__eq__', 'not': '__ne__', 'gt': '__gt__', 'ge': '__ge__', 'gte': '__ge__', 'lt': '__lt__', 'lte': '__le__', 'le': '__le__'}

auto_compute_server_default class-attribute instance-attribute

auto_compute_server_default = False

explicit_none instance-attribute

explicit_none = default is None

server_default instance-attribute

server_default = server_default

default instance-attribute

default = default

no_copy class-attribute instance-attribute

no_copy = False

read_only class-attribute instance-attribute

read_only = False

inject_default_on_partial_update class-attribute instance-attribute

inject_default_on_partial_update = False

inherit class-attribute instance-attribute

inherit = True

skip_absorption_check class-attribute instance-attribute

skip_absorption_check = False

skip_reflection_type_check class-attribute instance-attribute

skip_reflection_type_check = False

field_type class-attribute instance-attribute

field_type = Any

factory class-attribute instance-attribute

factory = None

__original_type__ class-attribute instance-attribute

__original_type__ = None

name class-attribute instance-attribute

name = ''

secret class-attribute instance-attribute

secret = False

exclude class-attribute instance-attribute

exclude = False

primary_key class-attribute instance-attribute

primary_key = False

autoincrement class-attribute instance-attribute

autoincrement = False

null class-attribute instance-attribute

null = False

index class-attribute instance-attribute

index = False

unique class-attribute instance-attribute

unique = False

registry property

registry

(Deprecated) Provides access to the Edgy Registry associated with the field's owner model.

This property is deprecated; use self.owner.meta.registry instead.

get_server_default

get_server_default()

Retrieves the server-side default value for the column.

This method determines the appropriate server default, considering explicitly defined server_default, the field's default value, and the auto_compute_server_default setting.

RETURNS DESCRIPTION
Any

The server default value, which can be None, a literal value,

Any

or a SQLAlchemy text construct.

Source code in edgy/core/db/fields/base.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
def get_server_default(self) -> Any:
    """
    Retrieves the server-side default value for the column.

    This method determines the appropriate server default, considering
    explicitly defined `server_default`, the field's `default` value,
    and the `auto_compute_server_default` setting.

    Returns:
        The server default value, which can be `None`, a literal value,
        or a SQLAlchemy text construct.
    """
    # Get the explicitly defined server_default.
    server_default = getattr(self, "server_default", Undefined)
    # If an explicit server_default was provided, return it.
    if server_default is not Undefined:
        return server_default

    # Get the Python default value.
    default = self.default
    # If the Python default is Undefined or None, there's no server default to compute.
    if default is Undefined or default is None:
        return None

    # Determine if auto-computation of server default is enabled based on
    # field settings and global configuration.
    if not callable(default):
        if self.auto_compute_server_default is None:
            # If auto_compute_server_default is None, use global settings and nullability.
            auto_compute_server_default: bool = (
                not self.null and settings.allow_auto_compute_server_defaults
            )
        elif self.auto_compute_server_default == "ignore_null":
            # If "ignore_null", use global settings regardless of nullability.
            auto_compute_server_default = settings.allow_auto_compute_server_defaults
        else:
            # Otherwise, use the explicit auto_compute_server_default setting.
            auto_compute_server_default = self.auto_compute_server_default
    else:
        # If the default is a callable, auto_compute_server_default must be explicitly True.
        auto_compute_server_default = self.auto_compute_server_default is True

    # If auto-computation is enabled, customize the default for server use; otherwise, return None.
    if auto_compute_server_default:
        return self.customize_default_for_server_default(default)
    return None

customize_default_for_server_default

customize_default_for_server_default(default)

Customizes the default value for use as a server-side default.

This method ensures that callable defaults are executed and that the resulting value is wrapped in a sqlalchemy.text construct for appropriate server-side default handling.

PARAMETER DESCRIPTION
default

The original default Python value, which might be a callable.

TYPE: Any

RETURNS DESCRIPTION
Any

A sqlalchemy.text object or a literal value suitable for a

Any

server-side default.

Source code in edgy/core/db/fields/base.py
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
def customize_default_for_server_default(self, default: Any) -> Any:
    """
    Customizes the default value for use as a server-side default.

    This method ensures that callable defaults are executed and that
    the resulting value is wrapped in a `sqlalchemy.text` construct
    for appropriate server-side default handling.

    Args:
        default: The original default Python value, which might be a callable.

    Returns:
        A `sqlalchemy.text` object or a literal value suitable for a
        server-side default.
    """
    # If the default is a callable, execute it to get the actual value.
    if callable(default):
        default = default()
    # Wrap the default value in a SQLAlchemy text construct with a bind parameter.
    return sqlalchemy.text(":value").bindparams(value=default)

get_columns_nullable

get_columns_nullable()

Determines if the database column(s) corresponding to this field should be nullable.

This method considers the field's explicit null setting and global FORCE_FIELDS_NULLABLE context variable.

RETURNS DESCRIPTION
bool

True if the column(s) should be nullable, False otherwise.

Source code in edgy/core/db/fields/base.py
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
def get_columns_nullable(self) -> bool:
    """
    Determines if the database column(s) corresponding to this field should be nullable.

    This method considers the field's explicit `null` setting and global
    `FORCE_FIELDS_NULLABLE` context variable.

    Returns:
        `True` if the column(s) should be nullable, `False` otherwise.
    """
    # If the field is explicitly nullable, return True.
    if self.null:
        return True
    # Get the set of fields that are forced to be nullable globally.
    force_fields = FORCE_FIELDS_NULLABLE.get()
    # Check if the current field (by owner name and field name, or by just field name)
    # is present in the forced nullable fields.
    return (self.owner.__name__, self.name) in force_fields or ("", self.name) in force_fields

operator_to_clause

operator_to_clause(field_name, operator, table, value)

Converts a given operator and value into a SQLAlchemy clause for filtering.

This method maps common operation codes to SQLAlchemy's ColumnElement methods, allowing for dynamic construction of database queries. It handles special cases like case-insensitive exact matches ('iexact') and null checks ('isnull'), as well as various string containment operations.

PARAMETER DESCRIPTION
field_name

The name of the column to apply the operator to.

TYPE: str

operator

The operation code (e.g., 'iexact', 'contains', 'isnull').

TYPE: str

table

The SQLAlchemy Table object the column belongs to.

TYPE: Table

value

The value to compare against.

TYPE: Any

RETURNS DESCRIPTION
Any

A SQLAlchemy clause suitable for use in a query's WHERE statement.

RAISES DESCRIPTION
KeyError

If 'field_name' does not correspond to an existing column in the table.

AttributeError

If the mapped operator does not exist as a method on the column.

Source code in edgy/core/db/fields/base.py
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
def operator_to_clause(
    self, field_name: str, operator: str, table: sqlalchemy.Table, value: Any
) -> Any:
    """
    Converts a given operator and value into a SQLAlchemy clause for filtering.

    This method maps common operation codes to SQLAlchemy's `ColumnElement` methods,
    allowing for dynamic construction of database queries. It handles special cases
    like case-insensitive exact matches ('iexact') and null checks ('isnull'),
    as well as various string containment operations.

    Args:
        field_name: The name of the column to apply the operator to.
        operator: The operation code (e.g., 'iexact', 'contains', 'isnull').
        table: The SQLAlchemy Table object the column belongs to.
        value: The value to compare against.

    Returns:
        A SQLAlchemy clause suitable for use in a query's WHERE statement.

    Raises:
        KeyError: If 'field_name' does not correspond to an existing column in the table.
        AttributeError: If the mapped operator does not exist as a method on the column.
    """
    # Get the SQLAlchemy Column object from the table using the field_name.
    column = table.columns[field_name]
    # Get the mapped operator from the operator_mapping, or use the original operator if not found.
    mapped_operator = self.operator_mapping.get(operator, operator)

    # Handle 'iexact' (case-insensitive exact match) specifically.
    match mapped_operator:
        case "iexact":
            # Define characters that need to be escaped in LIKE/ILIKE patterns.
            escape_characters = ["%", "_"]
            # Check if the value contains any of the escape characters.
            has_escaped_character = any(char in value for char in escape_characters)

            if has_escaped_character:
                # If escaped characters are present, escape backslashes first, then the specific escape characters.
                processed_value = value.replace("\\", "\\\\")
                for char in escape_characters:
                    processed_value = processed_value.replace(char, f"\\{char}")
                # Use ilike with an explicit escape character.
                return column.ilike(processed_value, escape="\\")
            else:
                # If no escape characters, use ilike directly.
                return column.ilike(value)
        case "isnull" | "isempty":
            # Handle 'isnull' (checking for NULL values).
            isnull = column == None  # noqa: E711
            # is_(None) doesn't work for all fields
            # column == None is required for IPAddressField, DateField, DateTimeField
            return isnull if value else sqlalchemy.not_(isnull)

        # Handle various string containment and prefix/suffix matching operations.
        case (
            "contains" | "icontains" | "startswith" | "endswith" | "istartswith" | "iendswith"
        ):
            # Apply the column method with autoescape enabled.
            return getattr(column, mapped_operator)(value, autoescape=True)

        case _:
            # For all other operators, directly apply the corresponding method
            # from the SQLAlchemy column object.
            return getattr(column, mapped_operator)(value)

is_required

is_required()

Checks if the field is required for model instantiation and database inserts.

A field is considered not required if it's a primary key with autoincrement, is nullable, has a server default, or has a Python default.

RETURNS DESCRIPTION
bool

True if the field is required, False otherwise.

Source code in edgy/core/db/fields/base.py
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
def is_required(self) -> bool:
    """
    Checks if the field is required for model instantiation and database inserts.

    A field is considered not required if it's a primary key with autoincrement,
    is nullable, has a server default, or has a Python default.

    Returns:
        `True` if the field is required, `False` otherwise.
    """
    # If the field is a primary key and is autoincrementing, it's not required.
    if self.primary_key and self.autoincrement:
        return False
    # The field is not required if it is nullable, has a server default (explicitly set),
    # or has a Python default.
    return not (
        self.null
        # Check if server_default is explicitly set and not Undefined.
        or (self.server_default is not None and self.server_default is not Undefined)
        or self.has_default()
    )

has_default

has_default()

Checks if the field has a default value set in Python.

This includes cases where default is None but explicitly set.

RETURNS DESCRIPTION
bool

True if a Python default is set, False otherwise.

Source code in edgy/core/db/fields/base.py
292
293
294
295
296
297
298
299
300
301
302
303
304
def has_default(self) -> bool:
    """
    Checks if the field has a default value set in Python.

    This includes cases where `default` is `None` but explicitly set.

    Returns:
        `True` if a Python default is set, `False` otherwise.
    """
    # A default exists if it's not None (unless explicit_none is True) and it's not Undefined.
    return bool(
        (self.default is not None or self.explicit_none) and self.default is not Undefined
    )

get_columns

get_columns(name)

Returns a sequence of SQLAlchemy Column objects associated with this field.

This is a base implementation that returns an empty list, as BaseField itself doesn't directly correspond to columns. Subclasses like Field will override this to return actual columns.

PARAMETER DESCRIPTION
name

The name of the field.

TYPE: str

RETURNS DESCRIPTION
Sequence[Column]

An empty sequence of SQLAlchemy Column objects.

Source code in edgy/core/db/fields/base.py
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
def get_columns(self, name: str) -> Sequence[sqlalchemy.Column]:
    """
    Returns a sequence of SQLAlchemy Column objects associated with this field.

    This is a base implementation that returns an empty list, as `BaseField`
    itself doesn't directly correspond to columns. Subclasses like `Field`
    will override this to return actual columns.

    Args:
        name: The name of the field.

    Returns:
        An empty sequence of SQLAlchemy Column objects.
    """
    return []

embed_field

embed_field(prefix, new_fieldname, owner=None, parent=None)

Embeds this field into a new context, potentially modifying its name and owner.

This method creates a copy of the field and updates its name and owner attributes. If a parent field specifies prefix_column_name, it updates the column_name of the copied field accordingly. Returns None if embedding is not supported for this field type.

PARAMETER DESCRIPTION
prefix

The prefix to be added to the field's new name.

TYPE: str

new_fieldname

The new full name of the field after embedding.

TYPE: str

owner

The new owner model class for the embedded field.

TYPE: type[BaseModelType] | None DEFAULT: None

parent

The parent field if this field is being embedded within another composite field.

TYPE: BaseFieldType | None DEFAULT: None

RETURNS DESCRIPTION
BaseField | None

A copy of the field with updated name and owner, or None if

BaseField | None

embedding is not permitted.

Source code in edgy/core/db/fields/base.py
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
def embed_field(
    self,
    prefix: str,
    new_fieldname: str,
    owner: type[BaseModelType] | None = None,
    parent: BaseFieldType | None = None,
) -> BaseField | None:
    """
    Embeds this field into a new context, potentially modifying its name
    and owner.

    This method creates a copy of the field and updates its `name` and `owner`
    attributes. If a `parent` field specifies `prefix_column_name`, it
    updates the `column_name` of the copied field accordingly. Returns `None`
    if embedding is not supported for this field type.

    Args:
        prefix: The prefix to be added to the field's new name.
        new_fieldname: The new full name of the field after embedding.
        owner: The new owner model class for the embedded field.
        parent: The parent field if this field is being embedded within another
                composite field.

    Returns:
        A copy of the field with updated `name` and `owner`, or `None` if
        embedding is not permitted.
    """
    # Create a shallow copy of the field.
    field_copy = copy.copy(self)
    # Update the name of the copied field.
    field_copy.name = new_fieldname
    # Set the new owner for the copied field.
    field_copy.owner = owner
    # If the parent field has a prefix_column_name attribute, apply it.
    if getattr(parent, "prefix_column_name", None):
        # If the copied field already has a column_name, prefix it.
        if getattr(field_copy, "column_name", None):
            field_copy.column_name = f"{parent.prefix_column_name}{field_copy.column_name}"  # type: ignore
        else:
            # Otherwise, construct the new column_name based on the prefix and new_fieldname.
            field_copy.column_name = (
                f"{parent.prefix_column_name}{new_fieldname[len(prefix) :]}"  # type: ignore
            )

    # Return the modified copy of the field.
    return field_copy

get_default_value

get_default_value()

Retrieves the default Python value for a single-valued field.

If the default is a callable, it is executed to get the value.

RETURNS DESCRIPTION
Any

The default value of the field, or None if no default is set.

Source code in edgy/core/db/fields/base.py
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
def get_default_value(self) -> Any:
    """
    Retrieves the default Python value for a single-valued field.

    If the default is a callable, it is executed to get the value.

    Returns:
        The default value of the field, or `None` if no default is set.
    """
    # Get the default value, defaulting to None if not present.
    default = getattr(self, "default", None)
    # If the default is a callable, call it to get the actual value.
    if callable(default):
        return default()
    # Otherwise, return the default value directly.
    return default

get_default_values

get_default_values(field_name, cleaned_data)

Retrieves default values for the field, to be applied during data cleaning.

For single-column fields, if the field name is not already present in cleaned_data, its default value is returned. Multi-value fields should override this method.

PARAMETER DESCRIPTION
field_name

The name of the field.

TYPE: str

cleaned_data

The dictionary of already cleaned data.

TYPE: dict[str, Any]

RETURNS DESCRIPTION
dict[str, Any]

A dictionary containing the default value for the field if it's not

dict[str, Any]

already in cleaned_data, otherwise an empty dictionary.

Source code in edgy/core/db/fields/base.py
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
def get_default_values(self, field_name: str, cleaned_data: dict[str, Any]) -> dict[str, Any]:
    """
    Retrieves default values for the field, to be applied during data cleaning.

    For single-column fields, if the field name is not already present in
    `cleaned_data`, its default value is returned. Multi-value fields
    should override this method.

    Args:
        field_name: The name of the field.
        cleaned_data: The dictionary of already cleaned data.

    Returns:
        A dictionary containing the default value for the field if it's not
        already in `cleaned_data`, otherwise an empty dictionary.
    """
    # for multidefaults overwrite in subclasses get_default_values to
    # parse default values differently
    # NOTE: multi value fields should always check here if defaults were already applied
    # NOTE: when build meta fields without columns this should be empty
    # If the field_name is already in cleaned_data, no default is needed.
    if field_name in cleaned_data:
        return {}
    # Return a dictionary with the field's default value.
    return {field_name: self.get_default_value()}

clean

clean(field_name, value, for_query=False)

Validates and transforms a Python value into a format suitable for database operations.

This method is used when preparing data for insertion or update into the database, or when building query predicates. Multi-column fields should return a dictionary mapping column names to their cleaned values.

PARAMETER DESCRIPTION
field_name

The logical name of the field.

TYPE: str

value

The Python value of the field.

TYPE: Any

for_query

If True, the cleaning is for query construction; otherwise, for saving.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
dict[str, Any]

dict[str, Any]: A dictionary where keys are database column names and values are their cleaned representations.

Source code in edgy/core/db/fields/types.py
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
def clean(self, field_name: str, value: Any, for_query: bool = False) -> dict[str, Any]:
    """
    Validates and transforms a Python value into a format suitable for database operations.

    This method is used when preparing data for insertion or update into the database,
    or when building query predicates. Multi-column fields should return a dictionary
    mapping column names to their cleaned values.

    Args:
        field_name (str): The logical name of the field.
        value (Any): The Python value of the field.
        for_query (bool): If `True`, the cleaning is for query construction; otherwise, for saving.

    Returns:
        dict[str, Any]: A dictionary where keys are database column names and values are
                        their cleaned representations.
    """
    return {}

to_model

to_model(field_name, value)

Converts database column values back into the Python representation for the Edgy model.

This is the inverse of clean. It takes raw values retrieved from the database and transforms them into the expected Python type for the model instance.

PARAMETER DESCRIPTION
field_name

The logical name of the field.

TYPE: str

value

The raw value(s) retrieved from the database.

TYPE: Any

RETURNS DESCRIPTION
dict[str, Any]

dict[str, Any]: A dictionary where keys are field names and values are their Python representations.

Source code in edgy/core/db/fields/types.py
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
def to_model(
    self,
    field_name: str,
    value: Any,
) -> dict[str, Any]:
    """
    Converts database column values back into the Python representation for the Edgy model.

    This is the inverse of `clean`. It takes raw values retrieved from the database
    and transforms them into the expected Python type for the model instance.

    Args:
        field_name (str): The logical name of the field.
        value (Any): The raw value(s) retrieved from the database.

    Returns:
        dict[str, Any]: A dictionary where keys are field names and values are
                        their Python representations.
    """
    return {field_name: value}

get_global_constraints

get_global_constraints(name, columns, schemes=())

Returns global SQLAlchemy constraints or indexes that apply across multiple columns or at the table level (e.g., unique constraints involving multiple fields).

PARAMETER DESCRIPTION
name

The logical name of the field.

TYPE: str

columns

The SQLAlchemy Column objects associated with this field.

TYPE: Sequence[Column]

schemes

Database schema names (if applicable).

TYPE: Sequence[str] DEFAULT: ()

RETURNS DESCRIPTION
Sequence[Constraint | Index]

Sequence[sqlalchemy.Constraint | sqlalchemy.Index]: A sequence of SQLAlchemy constraints or indexes.

Source code in edgy/core/db/fields/types.py
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
def get_global_constraints(
    self,
    name: str,
    columns: Sequence[sqlalchemy.Column],
    schemes: Sequence[str] = (),
) -> Sequence[sqlalchemy.Constraint | sqlalchemy.Index]:
    """
    Returns global SQLAlchemy constraints or indexes that apply across multiple columns
    or at the table level (e.g., unique constraints involving multiple fields).

    Args:
        name (str): The logical name of the field.
        columns (Sequence[sqlalchemy.Column]): The SQLAlchemy Column objects associated with this field.
        schemes (Sequence[str]): Database schema names (if applicable).

    Returns:
        Sequence[sqlalchemy.Constraint | sqlalchemy.Index]: A sequence of SQLAlchemy constraints or indexes.
    """
    return []

get_embedded_fields

get_embedded_fields(field_name, fields)

Defines and returns additional fields that should be "embedded" or added to the model's schema dynamically.

This is useful for fields that generate related or sub-fields. The returned fields should be new instances or copies, and their owner should be set.

PARAMETER DESCRIPTION
field_name

The logical name of the field.

TYPE: str

fields

The existing fields defined on the model.

TYPE: dict[str, BaseFieldType]

RETURNS DESCRIPTION
dict[str, BaseFieldType]

dict[str, BaseFieldType]: A dictionary of new field names to BaseFieldType instances.

Source code in edgy/core/db/fields/types.py
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
def get_embedded_fields(
    self, field_name: str, fields: dict[str, BaseFieldType]
) -> dict[str, BaseFieldType]:
    """
    Defines and returns additional fields that should be "embedded" or added
    to the model's schema dynamically.

    This is useful for fields that generate related or sub-fields. The returned
    fields should be new instances or copies, and their `owner` should be set.

    Args:
        field_name (str): The logical name of the field.
        fields (dict[str, BaseFieldType]): The existing fields defined on the model.

    Returns:
        dict[str, BaseFieldType]: A dictionary of new field names to `BaseFieldType` instances.
    """
    return {}

get_column_names

get_column_names(name='')

Retrieves the set of database column names associated with this field.

PARAMETER DESCRIPTION
name

The logical name of the field. If empty, uses self.name.

TYPE: str DEFAULT: ''

RETURNS DESCRIPTION
frozenset[str]

frozenset[str]: A frozenset of database column names.

Source code in edgy/core/db/fields/types.py
322
323
324
325
326
327
328
329
330
331
332
333
334
def get_column_names(self, name: str = "") -> frozenset[str]:
    """
    Retrieves the set of database column names associated with this field.

    Args:
        name (str): The logical name of the field. If empty, uses `self.name`.

    Returns:
        frozenset[str]: A frozenset of database column names.
    """
    if name:
        return cast("MetaInfo", self.owner.meta).field_to_column_names[name]
    return cast("MetaInfo", self.owner.meta).field_to_column_names[self.name]