MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / column_property

Function column_property

lib/sqlalchemy/orm/_orm_constructors.py:459–629  ·  view source on GitHub ↗

r"""Provide a column-level property for use with a mapping. With Declarative mappings, :func:`_orm.column_property` is used to map read-only SQL expressions to a mapped class. When using Imperative mappings, :func:`_orm.column_property` also takes on the role of mapping table colum

(
    column: _ORMColumnExprArgument[_T],
    *additional_columns: _ORMColumnExprArgument[Any],
    group: Optional[str] = None,
    deferred: bool = False,
    raiseload: bool = False,
    comparator_factory: Optional[Type[PropComparator[_T]]] = None,
    init: Union[_NoArg, bool] = _NoArg.NO_ARG,
    repr: Union[_NoArg, bool] = _NoArg.NO_ARG,  # noqa: A002
    default: Optional[Any] = _NoArg.NO_ARG,
    default_factory: Union[_NoArg, Callable[[], _T]] = _NoArg.NO_ARG,
    compare: Union[_NoArg, bool] = _NoArg.NO_ARG,
    kw_only: Union[_NoArg, bool] = _NoArg.NO_ARG,
    hash: Union[_NoArg, bool, None] = _NoArg.NO_ARG,  # noqa: A002
    active_history: bool = False,
    expire_on_flush: bool = True,
    info: Optional[_InfoType] = None,
    doc: Optional[str] = None,
    dataclass_metadata: Union[_NoArg, Mapping[Any, Any], None] = _NoArg.NO_ARG,
)

Source from the content-addressed store, hash-verified

457 }
458)
459def column_property(
460 column: _ORMColumnExprArgument[_T],
461 *additional_columns: _ORMColumnExprArgument[Any],
462 group: Optional[str] = None,
463 deferred: bool = False,
464 raiseload: bool = False,
465 comparator_factory: Optional[Type[PropComparator[_T]]] = None,
466 init: Union[_NoArg, bool] = _NoArg.NO_ARG,
467 repr: Union[_NoArg, bool] = _NoArg.NO_ARG, # noqa: A002
468 default: Optional[Any] = _NoArg.NO_ARG,
469 default_factory: Union[_NoArg, Callable[[], _T]] = _NoArg.NO_ARG,
470 compare: Union[_NoArg, bool] = _NoArg.NO_ARG,
471 kw_only: Union[_NoArg, bool] = _NoArg.NO_ARG,
472 hash: Union[_NoArg, bool, None] = _NoArg.NO_ARG, # noqa: A002
473 active_history: bool = False,
474 expire_on_flush: bool = True,
475 info: Optional[_InfoType] = None,
476 doc: Optional[str] = None,
477 dataclass_metadata: Union[_NoArg, Mapping[Any, Any], None] = _NoArg.NO_ARG,
478) -> MappedSQLExpression[_T]:
479 r"""Provide a column-level property for use with a mapping.
480
481 With Declarative mappings, :func:`_orm.column_property` is used to
482 map read-only SQL expressions to a mapped class.
483
484 When using Imperative mappings, :func:`_orm.column_property` also
485 takes on the role of mapping table columns with additional features.
486 When using fully Declarative mappings, the :func:`_orm.mapped_column`
487 construct should be used for this purpose.
488
489 With Declarative Dataclass mappings, :func:`_orm.column_property`
490 is considered to be **read only**, and will not be included in the
491 Dataclass ``__init__()`` constructor.
492
493 The :func:`_orm.column_property` function returns an instance of
494 :class:`.ColumnProperty`.
495
496 .. seealso::
497
498 :ref:`mapper_column_property_sql_expressions` - general use of
499 :func:`_orm.column_property` to map SQL expressions
500
501 :ref:`orm_imperative_table_column_options` - usage of
502 :func:`_orm.column_property` with Imperative Table mappings to apply
503 additional options to a plain :class:`_schema.Column` object
504
505 :param \*cols:
506 list of Column objects to be mapped.
507
508 :param active_history=False:
509
510 Used only for Imperative Table mappings, or legacy-style Declarative
511 mappings (i.e. which have not been upgraded to
512 :func:`_orm.mapped_column`), for column-based attributes that are
513 expected to be writeable; use :func:`_orm.mapped_column` with
514 :paramref:`_orm.mapped_column.active_history` for Declarative mappings.
515 See that parameter for functional details.
516

Callers 15

UserClass · 0.90
TestTicket9628Class · 0.90
TestTableClass · 0.90
FooClass · 0.90
thingMethod · 0.90
UserClass · 0.90
_fixtureMethod · 0.90
_func_fixtureMethod · 0.90
deferred_fixtureMethod · 0.90
test_column_propertyMethod · 0.90

Calls 2

MappedSQLExpressionClass · 0.85
_AttributeOptionsClass · 0.85

Tested by 15

thingMethod · 0.72
_fixtureMethod · 0.72
_func_fixtureMethod · 0.72
deferred_fixtureMethod · 0.72
test_column_propertyMethod · 0.72
test_column_propertyMethod · 0.72
_fixtureMethod · 0.72
setup_mappersMethod · 0.72