@@ -61,7 +61,7 @@ class SchemasMixin:
6161
6262 It is currently implemented as a mixin rather than directly provided on the
6363 base class because it requires that the host `DatabaseClient` instance have a
64- `sqlalchemy` metadata object handle, and not all backends support this.
64+ `sqlalchemy` engine object handle, and not all backends support this.
6565
6666 If we are willing to forgo the ability to actually make queries using the
6767 SQLAlchemy ORM, we could instead use an SQL agnostic version.
@@ -79,9 +79,9 @@ def schemas(self):
7979 def get_schemas ():
8080 if not getattr (self , "_schemas" , None ):
8181 assert (
82- getattr (self , "_sqlalchemy_metadata " , None ) is not None
83- ), f"`{ self .__class__ .__name__ } ` instances do not provide the required sqlalchemy metadata for schema exploration."
84- self ._schemas = Schemas (self ._sqlalchemy_metadata )
82+ getattr (self , "_sqlalchemy_engine " , None ) is not None
83+ ), f"`{ self .__class__ .__name__ } ` instances do not provide the required sqlalchemy engine for schema exploration."
84+ self ._schemas = Schemas (self ._sqlalchemy_engine )
8585 return self ._schemas
8686
8787 return Proxy (get_schemas )
@@ -138,22 +138,20 @@ class Schemas:
138138 An object which has as its attributes all of the schemas in a nominated database.
139139
140140 Args:
141- metadata (sqlalchemy.MetaData ): A SQL Alchemy `MetaData ` instance
141+ engine (sqlalchemy.Engine ): A SQL Alchemy `Engine ` instance
142142 configured for the nominated database.
143143 """
144144
145- def __init__ (self , metadata ):
146- self ._metadata = metadata
145+ def __init__ (self , engine ):
146+ self ._engine = engine
147147 self ._schema_names = None
148148 self ._schema_cache = {}
149149
150150 @property
151151 def all (self ):
152152 "list<str>: The list of schema names."
153153 if self ._schema_names is None :
154- self ._schema_names = sqlalchemy .inspect (
155- self ._metadata .bind
156- ).get_schema_names ()
154+ self ._schema_names = sqlalchemy .inspect (self ._engine ).get_schema_names ()
157155 return self ._schema_names
158156
159157 def __dir__ (self ):
@@ -162,9 +160,7 @@ def __dir__(self):
162160 def __getattr__ (self , value ):
163161 if value in self .all :
164162 if value not in self ._schema_cache :
165- self ._schema_cache [value ] = Schema (
166- metadata = self ._metadata , schema = value
167- )
163+ self ._schema_cache [value ] = Schema (engine = self ._engine , schema = value )
168164 return self ._schema_cache [value ]
169165 raise AttributeError (f"No such schema { value } " )
170166
@@ -184,13 +180,13 @@ class Schema:
184180 An object which has as its attributes all of the tables in a nominated database schema.
185181
186182 Args:
187- metadata (sqlalchemy.MetaData ): A SQL Alchemy `MetaData ` instance
183+ engine (sqlalchemy.Engine ): A SQL Alchemy `Engine ` instance
188184 configured for the nominated database.
189185 schema (str): The schema within which to expose tables.
190186 """
191187
192- def __init__ (self , metadata , schema ):
193- self ._metadata = metadata
188+ def __init__ (self , engine , schema ):
189+ self ._engine = engine
194190 self ._schema = schema
195191 self ._table_cache = {}
196192 self ._table_names = None
@@ -199,7 +195,7 @@ def __init__(self, metadata, schema):
199195 def all (self ):
200196 """list<str>: The table names in this database schema."""
201197 if self ._table_names is None :
202- self ._table_names = sqlalchemy .inspect (self ._metadata . bind ).get_table_names (
198+ self ._table_names = sqlalchemy .inspect (self ._engine ).get_table_names (
203199 self ._schema
204200 )
205201 return self ._table_names
0 commit comments