diff options
| author | Federico Caselli <cfederico87@gmail.com> | 2020-04-13 12:16:21 +0200 |
|---|---|---|
| committer | Federico Caselli <cfederico87@gmail.com> | 2020-06-03 20:53:47 +0200 |
| commit | 8dcf876fe9a06f3360b8d260459cdff050b2aa00 (patch) | |
| tree | ab6a0493ef1c1b7b9d869df3e3b36d9ee557c318 /lib/sqlalchemy/engine | |
| parent | 7f0cb933f2b1979a8d781855618b7fd3bf280037 (diff) | |
| download | sqlalchemy-8dcf876fe9a06f3360b8d260459cdff050b2aa00.tar.gz | |
Added reflection method :meth:`.Inspector.get_sequence_names`
Added new reflection method :meth:`.Inspector.get_sequence_names` which
returns all the sequences defined. Support for this method has been added
to the backend that support :class:`.Sequence`: PostgreSql, Oracle,
MSSQL and MariaDB >= 10.3.
Fixes: #2056
Change-Id: I0949696a39aa28c849edf2504779241f7443778a
Diffstat (limited to 'lib/sqlalchemy/engine')
| -rw-r--r-- | lib/sqlalchemy/engine/interfaces.py | 13 | ||||
| -rw-r--r-- | lib/sqlalchemy/engine/reflection.py | 35 |
2 files changed, 41 insertions, 7 deletions
diff --git a/lib/sqlalchemy/engine/interfaces.py b/lib/sqlalchemy/engine/interfaces.py index 49d9af966..59b9cd4ce 100644 --- a/lib/sqlalchemy/engine/interfaces.py +++ b/lib/sqlalchemy/engine/interfaces.py @@ -304,8 +304,17 @@ class Dialect(object): def get_view_names(self, connection, schema=None, **kw): """Return a list of all view names available in the database. - schema: - Optional, retrieve names from a non-default schema. + :param schema: schema name to query, if not the default schema. + """ + + raise NotImplementedError() + + def get_sequence_names(self, connection, schema=None, **kw): + """Return a list of all sequence names available in the database. + + :param schema: schema name to query, if not the default schema. + + .. versionadded:: 1.4 """ raise NotImplementedError() diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py index 344d5511d..fded37b2a 100644 --- a/lib/sqlalchemy/engine/reflection.py +++ b/lib/sqlalchemy/engine/reflection.py @@ -255,11 +255,6 @@ class Inspector(object): support named schemas, behavior is undefined if ``schema`` is not passed as ``None``. For special quoting, use :class:`.quoted_name`. - :param order_by: Optional, may be the string "foreign_key" to sort - the result on foreign key dependencies. Does not automatically - resolve cycles, and will raise :class:`.CircularDependencyError` - if cycles exist. - .. seealso:: :meth:`_reflection.Inspector.get_sorted_table_and_fkc_names` @@ -276,6 +271,10 @@ class Inspector(object): def has_table(self, table_name, schema=None): """Return True if the backend has a table of the given name. + + :param table_name: name of the table to check + :param schema: schema name to query, if not the default schema. + .. versionadded:: 1.4 """ @@ -283,6 +282,19 @@ class Inspector(object): with self._operation_context() as conn: return self.dialect.has_table(conn, table_name, schema) + def has_sequence(self, sequence_name, schema=None): + """Return True if the backend has a table of the given name. + + :param sequence_name: name of the table to check + :param schema: schema name to query, if not the default schema. + + .. versionadded:: 1.4 + + """ + # TODO: info_cache? + with self._operation_context() as conn: + return self.dialect.has_sequence(conn, sequence_name, schema) + def get_sorted_table_and_fkc_names(self, schema=None): """Return dependency-sorted table and foreign key constraint names in referred to within a particular schema. @@ -401,6 +413,19 @@ class Inspector(object): conn, schema, info_cache=self.info_cache ) + def get_sequence_names(self, schema=None): + """Return all sequence names in `schema`. + + :param schema: Optional, retrieve names from a non-default schema. + For special quoting, use :class:`.quoted_name`. + + """ + + with self._operation_context() as conn: + return self.dialect.get_sequence_names( + conn, schema, info_cache=self.info_cache + ) + def get_view_definition(self, view_name, schema=None): """Return definition for `view_name`. |
