diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-01-19 15:14:46 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-01-19 15:14:46 -0500 |
commit | e48d97b46a4ad19d4efe3c22d23d89d0ed92a310 (patch) | |
tree | de49a1c2d32807cca6a37946e972f9a1012bbade /lib/sqlalchemy/sql/schema.py | |
parent | 0a180a58baa4532cb07d9ca94057392a27b42421 (diff) | |
download | sqlalchemy-e48d97b46a4ad19d4efe3c22d23d89d0ed92a310.tar.gz |
Document Table/Column accessors
As Sphinx will not allow us to add attributes to the
.rst file while maintaining order, these have to be added
as class-level attributes.
Inlcude notes that "index" and "unique" parameters, while
indicated by Column.index / Column.unique, do not actually
indicate if the column is part of an index.
Fixes: #5851
Change-Id: I18fbaf6c504c4b1005b4c51057f80397fb48b387
Diffstat (limited to 'lib/sqlalchemy/sql/schema.py')
-rw-r--r-- | lib/sqlalchemy/sql/schema.py | 104 |
1 files changed, 103 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index f420eb621..5ca73dac3 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -482,6 +482,44 @@ class Table(DialectKWArgs, SchemaItem, TableClause): __visit_name__ = "table" + constraints = None + """A collection of all :class:`_schema.Constraint` objects associated with + this :class:`_schema.Table`. + + Includes :class:`_schema.PrimaryKeyConstraint`, + :class:`_schema.ForeignKeyConstraint`, :class:`_schema.UniqueConstraint`, + :class:`_schema.CheckConstraint`. A separate collection + :attr:`_schema.Table.foreign_key_constraints` refers to the collection + of all :class:`_schema.ForeignKeyConstraint` objects, and the + :attr:`_schema.Table.primary_key` attribute refers to the single + :class:`_schema.PrimaryKeyConstraint` associated with the + :class:`_schema.Table`. + + .. seealso:: + + :attr:`_schema.Table.constraints` + + :attr:`_schema.Table.primary_key` + + :attr:`_schema.Table.foreign_key_constraints` + + :attr:`_schema.Table.indexes` + + :class:`_reflection.Inspector` + + + """ + + indexes = None + """A collection of all :class:`_schema.Index` objects associated with this + :class:`_schema.Table`. + + .. seealso:: + + :meth:`_reflection.Inspector.get_indexes` + + """ + _traverse_internals = TableClause._traverse_internals + [ ("schema", InternalTraversal.dp_string) ] @@ -683,7 +721,14 @@ class Table(DialectKWArgs, SchemaItem, TableClause): :class:`_schema.ForeignKey` objects currently associated. - .. versionadded:: 1.0.0 + + .. seealso:: + + :attr:`_schema.Table.constraints` + + :attr:`_schema.Table.foreign_keys` + + :attr:`_schema.Table.indexes` """ return set(fkc.constraint for fkc in self.foreign_keys) @@ -1261,6 +1306,13 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause): contain multiple columns, use the :class:`.Index` construct instead. + .. note:: the :attr:`_schema.Column.index` attribute on + :class:`_schema.Column` + **does not indicate** if this column is indexed or not, only + if this flag was explicitly set here. To view indexes on + a column, view the :attr:`_schema.Table.indexes` collection + or use :meth:`_reflection.Inspector.get_indexes`. + :param info: Optional data dictionary which will be populated into the :attr:`.SchemaItem.info` attribute of this object. @@ -1363,6 +1415,17 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause): an explicit name, use the :class:`.UniqueConstraint` or :class:`.Index` constructs explicitly. + .. note:: the :attr:`_schema.Column.unique` attribute on + :class:`_schema.Column` + **does not indicate** if this column has a unique constraint or + not, only if this flag was explicitly set here. To view + indexes and unique constraints that may involve this column, + view the + :attr:`_schema.Table.indexes` and/or + :attr:`_schema.Table.constraints` collections or use + :meth:`_reflection.Inspector.get_indexes` and/or + :meth:`_reflection.Inspector.get_unique_constraints` + :param system: When ``True``, indicates this is a "system" column, that is a column which is automatically made available by the database, and should not be included in the columns list for a @@ -1490,6 +1553,45 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause): self._extra_kwargs(**kwargs) + foreign_keys = None + """A collection of all :class:`_schema.ForeignKey` marker objects + associated with this :class:`_schema.Column`. + + Each object is a member of a :class:`_schema.Table`-wide + :class:`_schema.ForeignKeyConstraint`. + + .. seealso:: + + :attr:`_schema.Table.foreign_keys` + + """ + + index = None + """The value of the :paramref:`_schema.Column.index` parameter. + + Does not indicate if this :class:`_schema.Column` is actually indexed + or not; use :attr:`_schema.Table.indexes`. + + .. seealso:: + + :attr:`_schema.Table.indexes` + """ + + unique = None + """The value of the :paramref:`_schema.Column.unique` parameter. + + Does not indicate if this :class:`_schema.Column` is actually subject to + a unique constraint or not; use :attr:`_schema.Table.indexes` and + :attr:`_schema.Table.constraints`. + + .. seealso:: + + :attr:`_schema.Table.indexes` + + :attr:`_schema.Table.constraints`. + + """ + def _extra_kwargs(self, **kwargs): self._validate_dialect_kwargs(kwargs) |