diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2023-02-15 18:19:18 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2023-02-15 18:19:18 +0000 |
| commit | e7de31117ef65a449ee2c07e22ae8607aad3e9a9 (patch) | |
| tree | 20884f8ceb3851a20a3c54112e7787bd21fb9f35 /lib/sqlalchemy/sql | |
| parent | d990235ec9f4f311bf97ba702ac8fe336d875e78 (diff) | |
| parent | 3d00c101be9feb73b87b8ad07ddc5bc14cd94cdb (diff) | |
| download | sqlalchemy-e7de31117ef65a449ee2c07e22ae8607aad3e9a9.tar.gz | |
Merge "Add ``Table.autoincrement_column``" into main
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/schema.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 976432721..2a713fea6 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -1001,10 +1001,32 @@ class Table( pass @util.ro_non_memoized_property - def _autoincrement_column(self) -> Optional[Column[Any]]: + def _autoincrement_column(self) -> Optional[Column[int]]: return self.primary_key._autoincrement_column @property + def autoincrement_column(self) -> Optional[Column[int]]: + """Returns the :class:`.Column` object which currently represents + the "auto increment" column, if any, else returns None. + + This is based on the rules for :class:`.Column` as defined by the + :paramref:`.Column.autoincrement` parameter, which generally means the + column within a single integer column primary key constraint that is + not constrained by a foreign key. If the table does not have such + a primary key constraint, then there's no "autoincrement" column. + A :class:`.Table` may have only one column defined as the + "autoincrement" column. + + .. versionadded:: 2.0.4 + + .. seealso:: + + :paramref:`.Column.autoincrement` + + """ + return self._autoincrement_column + + @property def key(self) -> str: """Return the 'key' for this :class:`_schema.Table`. @@ -4756,7 +4778,7 @@ class PrimaryKeyConstraint(ColumnCollectionConstraint): return list(self._columns) @util.ro_memoized_property - def _autoincrement_column(self) -> Optional[Column[Any]]: + def _autoincrement_column(self) -> Optional[Column[int]]: def _validate_autoinc(col: Column[Any], autoinc_true: bool) -> bool: if col.type._type_affinity is None or not issubclass( col.type._type_affinity, |
