From a0e0f4c289b46c0c9a051c08d7f9a1929e0e30ce Mon Sep 17 00:00:00 2001 From: Ilya Pekelny Date: Thu, 24 Jul 2014 19:27:18 +0300 Subject: Public inspector method to load enum list Provide opportunity to get enums list via an inspector instance public interface. --- lib/sqlalchemy/dialects/postgresql/base.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/dialects/postgresql/base.py') diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 5ff2f7c61..3356e9d4b 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1574,6 +1574,12 @@ class PGInspector(reflection.Inspector): return self.dialect.get_table_oid(self.bind, table_name, schema, info_cache=self.info_cache) + def load_enums(self, conn, schema=None): + """Return a enums list. + + A per-database and per-schema enums list.""" + schema = schema or self.default_schema_name + return self.dialect._load_enums(conn, schema) class CreateEnumType(schema._CreateDropBase): @@ -2424,7 +2430,8 @@ class PGDialect(default.DefaultDialect): for name, uc in uniques.items() ] - def _load_enums(self, connection): + def _load_enums(self, connection, schema=None): + schema = schema or self.default_schema_name if not self.supports_native_enum: return {} @@ -2440,8 +2447,9 @@ class PGDialect(default.DefaultDialect): LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace LEFT JOIN pg_catalog.pg_enum e ON t.oid = e.enumtypid WHERE t.typtype = 'e' + AND n.nspname = '%s' ORDER BY "name", e.oid -- e.oid gives us label order - """ + """ % schema s = sql.text(SQL_ENUMS, typemap={ 'attname': sqltypes.Unicode, -- cgit v1.2.1