diff options
63 files changed, 231 insertions, 191 deletions
@@ -31,6 +31,12 @@ trip over synonyms (and others) that are named after the column's actual "key" (since, column_prefix means "dont use the key"). - sql + - MetaData can now be constructed with an engine or url as the first + argument, just like BoundMetaData + - BoundMetaData is now deprecated, and MetaData is a direct substitute. + - DynamicMetaData has been renamed to ThreadLocalMetaData. the + DynamicMetaData name is deprecated and is an alias for ThreadLocalMetaData + or a regular MetaData if threadlocal=False - MetaData and all SchemaItems are safe to use with pickle. slow table reflections can be dumped into a pickled file to be reused later. Just reconnect the engine to the metadata after unpickling. [ticket:619] diff --git a/doc/build/content/dbengine.txt b/doc/build/content/dbengine.txt index 203968ae4..5f6e78d10 100644 --- a/doc/build/content/dbengine.txt +++ b/doc/build/content/dbengine.txt @@ -252,7 +252,7 @@ Using "bound" metadata: {python title="Implicit Execution Using Engine-Bound SQL Construct"} engine = create_engine('sqlite:///:memory:') - meta = BoundMetaData(engine) + meta = MetaData(engine) table = Table('mytable', meta, Column('col1', Integer), Column('col2', String(20))) r = table.insert().execute(col1=5, col2='some record') diff --git a/doc/build/content/metadata.txt b/doc/build/content/metadata.txt index 01d5646cc..3f13a3c69 100644 --- a/doc/build/content/metadata.txt +++ b/doc/build/content/metadata.txt @@ -13,7 +13,7 @@ A collection of metadata entities is stored in an object aptly named `MetaData`. {python} from sqlalchemy import * - metadata = MetaData(name='my metadata') + metadata = MetaData() Then to construct a Table, use the `Table` class: @@ -121,21 +121,26 @@ And `Table` provides an interface to the table's properties as well as that of i A MetaData object can be associated with one or more Engine instances. This allows the MetaData and the elements within it to perform operations automatically, using the connection resources of that Engine. This includes being able to "reflect" the columns of tables, as well as to perform create and drop operations without needing to pass an `Engine` or `Connection` around. It also allows SQL constructs to be created which know how to execute themselves (called "implicit execution"). -To bind `MetaData` to a single `Engine`, use `BoundMetaData`: +To bind `MetaData` to a single `Engine`, supply an Engine when creating the MetaData, or use the `.connect()` method: {python} engine = create_engine('sqlite://', **kwargs) - # create BoundMetaData from an Engine - meta = BoundMetaData(engine) + # create MetaData with an Engine + meta = MetaData(engine) # create the Engine and MetaData in one step - meta = BoundMetaData('postgres://db/', **kwargs) + meta = MetaData('postgres://db/', **kwargs) + + # or bind later + meta = MetaData() + # ... + meta.connect(engine) Another form of `MetaData` exits which can connect to an engine within the current thread (or "on a per-thread basis"), allowing other threads to be connected to different engines simultaneously: {python} - meta = DynamicMetaData() + meta = ThreadLocalMetaData() # In thread 1, connect to an existing Engine meta.connect(engine) @@ -143,11 +148,11 @@ Another form of `MetaData` exits which can connect to an engine within the curre # Meanwhile in thread 2, create a new Engine and connect meta.connect('mysq://user@host/dsn') -`DynamicMetaData` is intended for applications that need to use the same set of `Tables` for many different database connections in the same process, such as a CherryPy web application which handles multiple application instances in one process. +`ThreadLocalMetaData` is intended for applications that need to use the same set of `Tables` for many different database connections in the same process, such as a CherryPy web application which handles multiple application instances in one process. #### Using the global Metadata object -Some users prefer to create `Table` objects without specifying a `MetaData` object, having Tables scoped on an application-wide basis. For them the `default_metadata` object and the `global_connect()` function is supplied. `default_metadata` is simply an instance of `DynamicMetaData` that exists within the `sqlalchemy` namespace, and `global_connect()` is a synonym for `default_metadata.connect()`. Defining a `Table` that has no `MetaData` argument will automatically use this default metadata as follows: +Some users prefer to create `Table` objects without specifying a `MetaData` object, having Tables scoped on an application-wide basis. For them the `default_metadata` object and the `global_connect()` function is supplied. `default_metadata` is simply an instance of `ThreadLocalMetaData` that exists within the `sqlalchemy` namespace, and `global_connect()` is a synonym for `default_metadata.connect()`. Defining a `Table` that has no `MetaData` argument will automatically use this default metadata as follows: {python} from sqlalchemy import * @@ -169,7 +174,7 @@ Some users prefer to create `Table` objects without specifying a `MetaData` obje #### Reflecting Tables -Once you have a `BoundMetaData` or a connected `DynamicMetaData`, you can create `Table` objects without specifying their columns, just their names, using `autoload=True`: +Once you have a connected `MetaData` or `ThreadLocalMetaData`, you can create `Table` objects without specifying their columns, just their names, using `autoload=True`: {python} >>> messages = Table('messages', meta, autoload = True) @@ -291,7 +296,7 @@ To force quoting for an identifier, set the "quote=True" flag on `Column` or `Ta Creating and dropping individual tables can be done via the `create()` and `drop()` methods of `Table`; these methods take an optional `connectable` parameter which references an `Engine` or a `Connection`. If not supplied, the `Engine` bound to the `MetaData` will be used, else an error is raised: {python} - meta = BoundMetaData('sqlite:///:memory:') + meta = MetaData('sqlite:///:memory:') employees = Table('employees', meta, Column('employee_id', Integer, primary_key=True), Column('employee_name', String(60), nullable=False, key='name'), @@ -560,7 +565,7 @@ A `Table` object created against a specific `MetaData` object can be re-created {python} # create two metadata - meta1 = BoundMetaData('sqlite:///querytest.db') + meta1 = MetaData('sqlite:///querytest.db') meta2 = MetaData() # load 'users' from the sqlite engine diff --git a/doc/build/content/plugins.txt b/doc/build/content/plugins.txt index b4a0bebae..b7fc74fdb 100644 --- a/doc/build/content/plugins.txt +++ b/doc/build/content/plugins.txt @@ -474,7 +474,7 @@ To use `objectstore`: import sqlalchemy.mods.threadlocal from sqlalchemy import * - metadata = BoundMetaData('sqlite:///') + metadata = MetaData('sqlite:///') user_table = Table('users', metadata, Column('user_id', Integer, primary_key=True), Column('user_name', String(50), nullable=False) @@ -501,7 +501,7 @@ To use `assign_mapper`: import sqlalchemy.mods.threadlocal from sqlalchemy import * - metadata = BoundMetaData('sqlite:///') + metadata = MetaData('sqlite:///') user_table = Table('users', metadata, Column('user_id', Integer, primary_key=True), Column('user_name', String(50), nullable=False) @@ -602,7 +602,7 @@ Full SqlSoup documentation is on the [SQLAlchemy Wiki](http://www.sqlalchemy.org **Author:** Jason Pellerin -The `ProxyEngine` is used to "wrap" an `Engine`, and via subclassing `ProxyEngine` one can instrument the functionality of an arbitrary `Engine` instance through the decorator pattern. It also provides a `connect()` method which will send all `Engine` requests to different underlying engines. Its functionality in that regard is largely superceded now by `DynamicMetaData` which is a better solution. +The `ProxyEngine` is used to "wrap" an `Engine`, and via subclassing `ProxyEngine` one can instrument the functionality of an arbitrary `Engine` instance through the decorator pattern. It also provides a `connect()` method which will send all `Engine` requests to different underlying engines. Its functionality in that regard is largely superceded now by `MetaData` which is a better solution. {python} from sqlalchemy.ext.proxy import ProxyEngine diff --git a/doc/build/content/sqlconstruction.txt b/doc/build/content/sqlconstruction.txt index 1996b5de4..e8077f5bd 100644 --- a/doc/build/content/sqlconstruction.txt +++ b/doc/build/content/sqlconstruction.txt @@ -9,11 +9,11 @@ Executing a `ClauseElement` structure can be performed in two general ways. You The examples below all include a dump of the generated SQL corresponding to the query object, as well as a dump of the statement's bind parameters. In all cases, bind parameters are shown as named parameters using the colon format (i.e. ':name'). When the statement is compiled into a database-specific version, the named-parameter statement and its bind values are converted to the proper paramstyle for that database automatically. -For this section, we will mostly use the implcit style of execution, meaning the `Table` objects are associated with an instance of `BoundMetaData`, and constructed `ClauseElement` objects support self-execution. Assume the following configuration: +For this section, we will mostly use the implcit style of execution, meaning the `Table` objects are associated with a bound instance of `MetaData`, and constructed `ClauseElement` objects support self-execution. Assume the following configuration: {python} from sqlalchemy import * - metadata = BoundMetaData('sqlite:///mydb.db', echo=True) + metadata = MetaData('sqlite:///mydb.db', echo=True) # a table to store users users = Table('users', metadata, diff --git a/doc/build/content/tutorial.txt b/doc/build/content/tutorial.txt index 63c28860d..464d3044b 100644 --- a/doc/build/content/tutorial.txt +++ b/doc/build/content/tutorial.txt @@ -82,15 +82,16 @@ Working with Database Objects {@name=schemasql} ### Defining Metadata, Binding to Engines {@name=metadata} -Configuring SQLAlchemy for your database consists of creating objects called `Tables`, each of which represent an actual table in the database. A collection of `Table` objects resides in a `MetaData` object which is essentially a table collection. We will create a handy form of `MetaData` that automatically connects to our `Engine` (connecting a schema object to an Engine is called *binding*): +Configuring SQLAlchemy for your database consists of creating objects called `Tables`, each of which represent an actual table in the database. A collection of `Table` objects resides in a `MetaData` object which is essentially a table collection. We will create a `MetaData` and connect it to our `Engine` (connecting a schema object to an Engine is called *binding*): {python} - >>> metadata = BoundMetaData(db) + >>> metadata = MetaData() + >>> metadata.connect(db) -An equivalent operation is to create the `BoundMetaData` object directly with an Engine URL, which calls the `create_engine` call for us: +An equivalent operation is to create the `MetaData` object directly with an Engine URL, which calls the `create_engine` call for us: {python} - >>> metadata = BoundMetaData('sqlite:///tutorial.db') + >>> metadata = MetaData('sqlite:///tutorial.db') Now, when we tell "metadata" about the tables in our database, we can issue CREATE statements for those tables, as well as execute SQL statements derived from them, without needing to open or close any connections; that will be all done automatically. @@ -107,7 +108,7 @@ With `metadata` as our established home for tables, lets make a Table for it: ... Column('password', String(10)) ... ) -As you might have guessed, we have just defined a table named `users` which has three columns: `user_id` (which is a primary key column), `user_name` and `password`. Currently it is just an object that doesn't necessarily correspond to an existing table in our database. To actually create the table, we use the `create()` method. To make it interesting, we will have SQLAlchemy echo the SQL statements it sends to the database, by setting the `echo` flag on the `Engine` associated with our `BoundMetaData`: +As you might have guessed, we have just defined a table named `users` which has three columns: `user_id` (which is a primary key column), `user_name` and `password`. Currently it is just an object that doesn't necessarily correspond to an existing table in our database. To actually create the table, we use the `create()` method. To make it interesting, we will have SQLAlchemy echo the SQL statements it sends to the database, by setting the `echo` flag on the `Engine` associated with our `MetaData`: {python} >>> metadata.engine.echo = True diff --git a/examples/adjacencytree/basic_tree.py b/examples/adjacencytree/basic_tree.py index 3f4f64e3f..9676fae89 100644 --- a/examples/adjacencytree/basic_tree.py +++ b/examples/adjacencytree/basic_tree.py @@ -3,7 +3,7 @@ from sqlalchemy import * from sqlalchemy.util import OrderedDict -metadata = BoundMetaData('sqlite:///', echo=True) +metadata = MetaData('sqlite:///', echo=True) trees = Table('treenodes', metadata, Column('node_id', Integer, Sequence('treenode_id_seq',optional=False), primary_key=True), diff --git a/examples/adjacencytree/byroot_tree.py b/examples/adjacencytree/byroot_tree.py index 5c5584d96..5ec055392 100644 --- a/examples/adjacencytree/byroot_tree.py +++ b/examples/adjacencytree/byroot_tree.py @@ -7,7 +7,7 @@ from sqlalchemy.util import OrderedDict engine = create_engine('sqlite:///:memory:', echo=True) -metadata = BoundMetaData(engine) +metadata = MetaData(engine) """create the treenodes table. This is ia basic adjacency list model table. One additional column, "root_node_id", references a "root node" row and is used diff --git a/examples/association/basic_association.py b/examples/association/basic_association.py index 5ce643671..fabfdfa78 100644 --- a/examples/association/basic_association.py +++ b/examples/association/basic_association.py @@ -17,7 +17,7 @@ logging.basicConfig(format='%(message)s') logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) engine = create_engine('sqlite://') -metadata = BoundMetaData(engine) +metadata = MetaData(engine) orders = Table('orders', metadata, Column('order_id', Integer, primary_key=True), diff --git a/examples/association/proxied_association.py b/examples/association/proxied_association.py index 31a64ce7a..2dd60158b 100644 --- a/examples/association/proxied_association.py +++ b/examples/association/proxied_association.py @@ -11,7 +11,7 @@ logging.basicConfig(format='%(message)s') #logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) engine = create_engine('sqlite://') -metadata = BoundMetaData(engine) +metadata = MetaData(engine) orders = Table('orders', metadata, Column('order_id', Integer, primary_key=True), diff --git a/examples/backref/backref_tree.py b/examples/backref/backref_tree.py index 5f1739673..7386d034c 100644 --- a/examples/backref/backref_tree.py +++ b/examples/backref/backref_tree.py @@ -1,6 +1,6 @@ from sqlalchemy import * -metadata = BoundMetaData('sqlite:///', echo=True) +metadata = MetaData('sqlite:///', echo=True) class Tree(object): def __init__(self, name='', father=None): diff --git a/examples/collections/large_collection.py b/examples/collections/large_collection.py index 743624e99..d592441ab 100644 --- a/examples/collections/large_collection.py +++ b/examples/collections/large_collection.py @@ -1,7 +1,7 @@ """illlustrates techniques for dealing with very large collections""" from sqlalchemy import * -meta = BoundMetaData('sqlite://', echo=True) +meta = MetaData('sqlite://', echo=True) org_table = Table('organizations', meta, Column('org_id', Integer, primary_key=True), diff --git a/examples/graphs/graph1.py b/examples/graphs/graph1.py index af75d0ff5..c2eec44f9 100644 --- a/examples/graphs/graph1.py +++ b/examples/graphs/graph1.py @@ -6,7 +6,7 @@ import logging logging.basicConfig() logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) -meta = BoundMetaData('sqlite://') +meta = MetaData('sqlite://') nodes = Table('nodes', meta, Column("nodeid", Integer, primary_key=True) diff --git a/examples/pickle/custom_pickler.py b/examples/pickle/custom_pickler.py index 34a2ff0e5..4b259c1f8 100644 --- a/examples/pickle/custom_pickler.py +++ b/examples/pickle/custom_pickler.py @@ -6,7 +6,7 @@ from cStringIO import StringIO from pickle import Pickler, Unpickler import threading -meta = BoundMetaData('sqlite://', echo=True) +meta = MetaData('sqlite://', echo=True) class MyExt(MapperExtension): def populate_instance(self, mapper, selectcontext, row, instance, identitykey, isnew): @@ -79,4 +79,4 @@ sess.clear() del MyPickler.sessions.current f = sess.query(Foo).get(f.id) -assert f.bar.data == 'some bar'
\ No newline at end of file +assert f.bar.data == 'some bar' diff --git a/examples/poly_assoc/poly_assoc.py b/examples/poly_assoc/poly_assoc.py index faeabd956..a2ac6140f 100644 --- a/examples/poly_assoc/poly_assoc.py +++ b/examples/poly_assoc/poly_assoc.py @@ -22,7 +22,7 @@ the associated target object from those which associate with it. from sqlalchemy import * -metadata = BoundMetaData('sqlite://', echo=False) +metadata = MetaData('sqlite://', echo=False) ####### # addresses table, class, 'addressable interface'. diff --git a/examples/poly_assoc/poly_assoc_fk.py b/examples/poly_assoc/poly_assoc_fk.py index 53cb5c81f..f3cedac72 100644 --- a/examples/poly_assoc/poly_assoc_fk.py +++ b/examples/poly_assoc/poly_assoc_fk.py @@ -21,7 +21,7 @@ poly_assoc_generic.py. from sqlalchemy import * -metadata = BoundMetaData('sqlite://', echo=False) +metadata = MetaData('sqlite://', echo=False) ####### # addresses table, class, 'addressable interface'. diff --git a/examples/poly_assoc/poly_assoc_generic.py b/examples/poly_assoc/poly_assoc_generic.py index b0418cd5c..9cc7321db 100644 --- a/examples/poly_assoc/poly_assoc_generic.py +++ b/examples/poly_assoc/poly_assoc_generic.py @@ -8,7 +8,7 @@ function "association" which creates a new polymorphic association from sqlalchemy import * -metadata = BoundMetaData('sqlite://', echo=False) +metadata = MetaData('sqlite://', echo=False) def association(cls, table): """create an association 'interface'.""" diff --git a/examples/polymorph/polymorph.py b/examples/polymorph/polymorph.py index 5ff1a6d41..231a9d8e4 100644 --- a/examples/polymorph/polymorph.py +++ b/examples/polymorph/polymorph.py @@ -4,7 +4,7 @@ import sets # this example illustrates a polymorphic load of two classes, where each class has a very # different set of properties -metadata = BoundMetaData('sqlite://', echo=True) +metadata = MetaData('sqlite://', echo=True) # a table to store companies companies = Table('companies', metadata, diff --git a/examples/polymorph/single.py b/examples/polymorph/single.py index 11455a590..dcdb3c890 100644 --- a/examples/polymorph/single.py +++ b/examples/polymorph/single.py @@ -1,6 +1,6 @@ from sqlalchemy import * -metadata = BoundMetaData('sqlite://', echo='debug') +metadata = MetaData('sqlite://', echo='debug') # a table to store companies companies = Table('companies', metadata, diff --git a/examples/vertical/vertical.py b/examples/vertical/vertical.py index 720a1934d..e9fff9163 100644 --- a/examples/vertical/vertical.py +++ b/examples/vertical/vertical.py @@ -5,7 +5,7 @@ fields that are all persisted in a normalized fashion.""" from sqlalchemy import * import datetime -e = BoundMetaData('sqlite://', echo=True) +e = MetaData('sqlite://', echo=True) # this table represents Entity objects. each Entity gets a row in this table, # with a primary key and a title. @@ -177,4 +177,4 @@ for entity in entities: for entity in entities: session.delete(entity) -session.flush()
\ No newline at end of file +session.flush() diff --git a/lib/sqlalchemy/ext/activemapper.py b/lib/sqlalchemy/ext/activemapper.py index 004caf849..2fcf44f61 100644 --- a/lib/sqlalchemy/ext/activemapper.py +++ b/lib/sqlalchemy/ext/activemapper.py @@ -1,5 +1,5 @@ from sqlalchemy import create_session, relation, mapper, \ - join, DynamicMetaData, class_mapper, \ + join, ThreadLocalMetaData, class_mapper, \ util, Integer from sqlalchemy import and_, or_ from sqlalchemy import Table, Column, ForeignKey @@ -14,7 +14,7 @@ import sys # # the "proxy" to the database engine... this can be swapped out at runtime # -metadata = DynamicMetaData("activemapper") +metadata = ThreadLocalMetaData("activemapper") try: objectstore = sqlalchemy.objectstore diff --git a/lib/sqlalchemy/ext/sqlsoup.py b/lib/sqlalchemy/ext/sqlsoup.py index a27ad5ac8..c320724ac 100644 --- a/lib/sqlalchemy/ext/sqlsoup.py +++ b/lib/sqlalchemy/ext/sqlsoup.py @@ -22,7 +22,7 @@ engine:: or, you can re-use an existing metadata:: - >>> db = SqlSoup(BoundMetaData(e)) + >>> db = SqlSoup(MetaData(e)) You can optionally specify a schema within the database for your SqlSoup:: @@ -490,7 +490,7 @@ class SqlSoup: if args or kwargs: raise ArgumentError('Extra arguments not allowed when metadata is given') else: - metadata = BoundMetaData(*args, **kwargs) + metadata = MetaData(*args, **kwargs) self._metadata = metadata self._cache = {} self.schema = None diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 5d3ca694b..868dcb7b0 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -17,13 +17,13 @@ objects as well as the visitor interface, so that the schema package *plugs in* to the SQL package. """ -from sqlalchemy import sql, types, exceptions,util, databases +from sqlalchemy import sql, types, exceptions, util, databases import sqlalchemy import copy, re, string __all__ = ['SchemaItem', 'Table', 'Column', 'ForeignKey', 'Sequence', 'Index', 'ForeignKeyConstraint', 'PrimaryKeyConstraint', 'CheckConstraint', 'UniqueConstraint', 'DefaultGenerator', 'Constraint', - 'MetaData', 'BoundMetaData', 'DynamicMetaData', 'SchemaVisitor', 'PassiveDefault', 'ColumnDefault'] + 'MetaData', 'ThreadLocalMetaData', 'BoundMetaData', 'DynamicMetaData', 'SchemaVisitor', 'PassiveDefault', 'ColumnDefault'] class SchemaItem(object): """Base class for items that define a database schema.""" @@ -127,7 +127,7 @@ class _TableSingleton(type): # backwards compatibility - get a BoundSchema associated with the engine engine = metadata if not hasattr(engine, '_legacy_metadata'): - engine._legacy_metadata = BoundMetaData(engine) + engine._legacy_metadata = MetaData(engine) metadata = engine._legacy_metadata elif metadata is not None and not isinstance(metadata, MetaData): # they left MetaData out, so assume its another SchemaItem, add it to *args @@ -1067,32 +1067,59 @@ class Index(SchemaItem): class MetaData(SchemaItem): """Represent a collection of Tables and their associated schema constructs.""" - def __init__(self, name=None, url=None, engine=None, **kwargs): + def __init__(self, engine_or_url=None, url=None, engine=None, **kwargs): """create a new MetaData object. + + engine_or_url + an Engine, or a string or URL instance which will be passed + to create_engine(), along with \**kwargs - this MetaData will + be bound to the resulting engine. - name - optional name for this MetaData instance. - url - a string or URL instance which will be passed to create_engine(), - along with \**kwargs - this MetaData will be bound to the resulting - engine. + deprecated. a string or URL instance which will be passed to + create_engine(), along with \**kwargs - this MetaData will be + bound to the resulting engine. engine - an Engine instance to which this MetaData will be bound. + deprecated. an Engine instance to which this MetaData will + be bound. case_sensitive - popped from \**kwargs, indicates default case sensitive setting for - all contained objects. defaults to True. + popped from \**kwargs, indicates default case sensitive + setting for all contained objects. defaults to True. + + name + deprecated, optional name for this MetaData instance. - """ + """ + + # transition from <= 0.3.8 signature: + # MetaData(name=None, url=None, engine=None) + # to 0.4 signature: + # MetaData(engine_or_url=None) + name = kwargs.get('name', None) + if engine_or_url is None: + engine_or_url = url or engine + elif 'name' in kwargs: + engine_or_url = engine_or_url or engine or url + else: + import sqlalchemy.engine as engine + import sqlalchemy.engine.url as url + if (not isinstance(engine_or_url, url.URL) and + not isinstance(engine_or_url, engine.Connectable)): + try: + url.make_url(engine_or_url) + except exceptions.ArgumentError: + # nope, must have been a name as 1st positional + name, engine_or_url = engine_or_url, (url or engine) + kwargs.pop('name', None) self.tables = {} self.name = name self._engine = None self._set_casing_strategy(name, kwargs) - if engine or url: - self.connect(engine or url, **kwargs) + if engine_or_url: + self.connect(engine_or_url, **kwargs) def __getstate__(self): return {'tables':self.tables, 'name':self.name, 'casesensitive':self._case_sensitive_setting} @@ -1188,32 +1215,23 @@ class MetaData(SchemaItem): return None return self._engine + class BoundMetaData(MetaData): - """``MetaData`` for which the first argument is a required Engine, url string, or URL instance. - - """ + """Deprecated. Use ``MetaData``.""" def __init__(self, engine_or_url, name=None, **kwargs): - from sqlalchemy.engine.url import URL - if isinstance(engine_or_url, basestring) or isinstance(engine_or_url, URL): - super(BoundMetaData, self).__init__(name=name, url=engine_or_url, **kwargs) - else: - super(BoundMetaData, self).__init__(name=name, engine=engine_or_url, **kwargs) - + super(BoundMetaData, self).__init__(engine_or_url=engine_or_url, + name=name, **kwargs) -class DynamicMetaData(MetaData): - """Build upon ``MetaData`` to provide the capability to bind to -multiple ``Engine`` implementations on a dynamically alterable, -thread-local basis. - """ - def __init__(self, name=None, threadlocal=True, **kwargs): - if threadlocal: - self.context = util.ThreadLocal() - else: - self.context = self +class ThreadLocalMetaData(MetaData): + """A ``MetaData`` that binds to multiple ``Engine`` implementations on a thread-local basis.""" + + def __init__(self, name=None, **kwargs): + self.context = util.ThreadLocal() self.__engines = {} - super(DynamicMetaData, self).__init__(name=name, **kwargs) + super(ThreadLocalMetaData, self).__init__(engine_or_url=None, + name=name, **kwargs) def connect(self, engine_or_url, **kwargs): from sqlalchemy.engine.url import URL @@ -1233,7 +1251,7 @@ thread-local basis. return hasattr(self.context, '_engine') and self.context._engine is not None def dispose(self): - """Dispose all ``Engines`` to which this ``DynamicMetaData`` has been connected.""" + """Dispose all ``Engines`` to which this ``ThreadLocalMetaData`` has been connected.""" for e in self.__engines.values(): e.dispose() @@ -1245,6 +1263,16 @@ thread-local basis. return None engine=property(_get_engine) + +def DynamicMetaData(name=None, threadlocal=True, **kw): + """Deprecated. Use ``MetaData`` or ``ThreadLocalMetaData``.""" + + if threadlocal: + return ThreadLocalMetaData(**kw) + else: + return MetaData(name=name, **kw) + + class SchemaVisitor(sql.ClauseVisitor): """Define the visiting for ``SchemaItem`` objects.""" @@ -1306,4 +1334,4 @@ class SchemaVisitor(sql.ClauseVisitor): """Visit a ``CheckConstraint`` on a ``Column``.""" pass -default_metadata = DynamicMetaData('default') +default_metadata = ThreadLocalMetaData(name='default') diff --git a/test/dialect/mysql.py b/test/dialect/mysql.py index 4972c8e24..d9227383f 100644 --- a/test/dialect/mysql.py +++ b/test/dialect/mysql.py @@ -325,12 +325,12 @@ class TypesTest(AssertMixin): columns = [Column('c%i' % (i + 1), t[0]) for i, t in enumerate(specs)] - m = BoundMetaData(db) + m = MetaData(db) t_table = Table('mysql_types', m, *columns) m.drop_all() m.create_all() - m2 = BoundMetaData(db) + m2 = MetaData(db) rt = Table('mysql_types', m2, autoload=True) #print diff --git a/test/dialect/postgres.py b/test/dialect/postgres.py index 254309d22..8a69f2453 100644 --- a/test/dialect/postgres.py +++ b/test/dialect/postgres.py @@ -28,35 +28,35 @@ class DomainReflectionTest(AssertMixin): @testbase.supported('postgres') def test_table_is_reflected(self): - metadata = BoundMetaData(db) + metadata = MetaData(db) table = Table('testtable', metadata, autoload=True) self.assertEquals(set(table.columns.keys()), set(['question', 'answer']), "Columns of reflected table didn't equal expected columns") self.assertEquals(table.c.answer.type.__class__, postgres.PGInteger) @testbase.supported('postgres') def test_domain_is_reflected(self): - metadata = BoundMetaData(db) + metadata = MetaData(db) table = Table('testtable', metadata, autoload=True) self.assertEquals(str(table.columns.answer.default.arg), '42', "Reflected default value didn't equal expected value") self.assertFalse(table.columns.answer.nullable, "Expected reflected column to not be nullable.") @testbase.supported('postgres') def test_table_is_reflected_alt_schema(self): - metadata = BoundMetaData(db) + metadata = MetaData(db) table = Table('testtable', metadata, autoload=True, schema='alt_schema') self.assertEquals(set(table.columns.keys()), set(['question', 'answer', 'anything']), "Columns of reflected table didn't equal expected columns") self.assertEquals(table.c.anything.type.__class__, postgres.PGInteger) @testbase.supported('postgres') def test_schema_domain_is_reflected(self): - metadata = BoundMetaData(db) + metadata = MetaData(db) table = Table('testtable', metadata, autoload=True, schema='alt_schema') self.assertEquals(str(table.columns.answer.default.arg), '0', "Reflected default value didn't equal expected value") self.assertTrue(table.columns.answer.nullable, "Expected reflected column to be nullable.") @testbase.supported('postgres') def test_crosschema_domain_is_reflected(self): - metadata = BoundMetaData(db) + metadata = MetaData(db) table = Table('crosschema', metadata, autoload=True) self.assertEquals(str(table.columns.answer.default.arg), '0', "Reflected default value didn't equal expected value") self.assertTrue(table.columns.answer.nullable, "Expected reflected column to be nullable.") @@ -64,14 +64,14 @@ class DomainReflectionTest(AssertMixin): class MiscTest(AssertMixin): @testbase.supported('postgres') def test_date_reflection(self): - m1 = BoundMetaData(testbase.db) + m1 = MetaData(testbase.db) t1 = Table('pgdate', m1, Column('date1', DateTime(timezone=True)), Column('date2', DateTime(timezone=False)) ) m1.create_all() try: - m2 = BoundMetaData(testbase.db) + m2 = MetaData(testbase.db) t2 = Table('pgdate', m2, autoload=True) assert t2.c.date1.type.timezone is True assert t2.c.date2.type.timezone is False @@ -80,7 +80,7 @@ class MiscTest(AssertMixin): @testbase.supported('postgres') def test_checksfor_sequence(self): - meta1 = BoundMetaData(testbase.db) + meta1 = MetaData(testbase.db) t = Table('mytable', meta1, Column('col1', Integer, Sequence('fooseq'))) try: @@ -93,7 +93,7 @@ class MiscTest(AssertMixin): def test_schema_reflection(self): """note: this test requires that the 'alt_schema' schema be separate and accessible by the test user""" - meta1 = BoundMetaData(testbase.db) + meta1 = MetaData(testbase.db) users = Table('users', meta1, Column('user_id', Integer, primary_key = True), Column('user_name', String(30), nullable = False), @@ -108,7 +108,7 @@ class MiscTest(AssertMixin): ) meta1.create_all() try: - meta2 = BoundMetaData(testbase.db) + meta2 = MetaData(testbase.db) addresses = Table('email_addresses', meta2, autoload=True, schema="alt_schema") users = Table('users', meta2, mustexist=True, schema="alt_schema") @@ -127,7 +127,7 @@ class MiscTest(AssertMixin): that PassiveDefault upon insert.""" try: - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) testbase.db.execute(""" CREATE TABLE speedy_users ( @@ -154,7 +154,7 @@ class TimezoneTest(AssertMixin): @testbase.supported('postgres') def setUpAll(self): global tztable, notztable, metadata - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) # current_timestamp() in postgres is assumed to return TIMESTAMP WITH TIMEZONE tztable = Table('tztable', metadata, diff --git a/test/engine/execute.py b/test/engine/execute.py index 33c252018..283006cfa 100644 --- a/test/engine/execute.py +++ b/test/engine/execute.py @@ -9,7 +9,7 @@ from sqlalchemy import * class ExecuteTest(testbase.PersistTest): def setUpAll(self): global users, metadata - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) users = Table('users', metadata, Column('user_id', INT, primary_key = True), Column('user_name', VARCHAR(20)), diff --git a/test/engine/reflection.py b/test/engine/reflection.py index a9a1f934e..344d5a94f 100644 --- a/test/engine/reflection.py +++ b/test/engine/reflection.py @@ -34,7 +34,7 @@ class ReflectionTest(PersistTest): deftype2, deftype3 = Integer, Integer defval2, defval3 = "15", "16" - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) users = Table('engine_users', meta, Column('user_id', INT, primary_key = True), @@ -108,7 +108,7 @@ class ReflectionTest(PersistTest): def testoverridecolumns(self): """test that you can override columns which contain foreign keys to other reflected tables""" - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) users = Table('users', meta, Column('id', Integer, primary_key=True), Column('name', String(30))) @@ -119,7 +119,7 @@ class ReflectionTest(PersistTest): meta.create_all() try: - meta2 = BoundMetaData(testbase.db) + meta2 = MetaData(testbase.db) a2 = Table('addresses', meta2, Column('user_id', Integer, ForeignKey('users.id')), autoload=True) @@ -129,7 +129,7 @@ class ReflectionTest(PersistTest): assert list(a2.c.user_id.foreign_keys)[0].parent is a2.c.user_id assert u2.join(a2).onclause == u2.c.id==a2.c.user_id - meta3 = BoundMetaData(testbase.db) + meta3 = MetaData(testbase.db) u3 = Table('users', meta3, autoload=True) a3 = Table('addresses', meta3, Column('user_id', Integer, ForeignKey('users.id')), @@ -143,7 +143,7 @@ class ReflectionTest(PersistTest): def testoverridecolumns2(self): """test that you can override columns which contain foreign keys to other reflected tables, where the foreign key column is also a primary key column""" - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) users = Table('users', meta, Column('id', Integer, primary_key=True), Column('name', String(30))) @@ -154,7 +154,7 @@ class ReflectionTest(PersistTest): meta.create_all() try: - meta2 = BoundMetaData(testbase.db) + meta2 = MetaData(testbase.db) a2 = Table('addresses', meta2, Column('id', Integer, ForeignKey('users.id'), primary_key=True, ), autoload=True) @@ -173,7 +173,7 @@ class ReflectionTest(PersistTest): #sess.save(add1) #sess.flush() - meta3 = BoundMetaData(testbase.db) + meta3 = MetaData(testbase.db) u3 = Table('users', meta3, autoload=True) a3 = Table('addresses', meta3, Column('id', Integer, ForeignKey('users.id'), primary_key=True), @@ -188,7 +188,7 @@ class ReflectionTest(PersistTest): @testbase.supported('mysql') def testmysqltypes(self): - meta1 = BoundMetaData(testbase.db) + meta1 = MetaData(testbase.db) table = Table( 'mysql_types', meta1, Column('id', Integer, primary_key=True), @@ -204,7 +204,7 @@ class ReflectionTest(PersistTest): try: table.drop(checkfirst=True) table.create() - meta2 = BoundMetaData(testbase.db) + meta2 = MetaData(testbase.db) t2 = Table('mysql_types', meta2, autoload=True) assert isinstance(t2.c.num1.type, mysql.MSInteger) assert t2.c.num1.type.unsigned @@ -281,7 +281,7 @@ class ReflectionTest(PersistTest): ) """) try: - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) table1 = Table("django_admin_log", meta, autoload=True) table2 = Table("django_content_type", meta, autoload=True) j = table1.join(table2) @@ -292,7 +292,7 @@ class ReflectionTest(PersistTest): def test_composite_fk(self): """test reflection of composite foreign keys""" - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) table = Table( 'multi', meta, Column('multi_id', Integer, primary_key=True), @@ -411,7 +411,7 @@ class ReflectionTest(PersistTest): testbase.db, autoload=True) def testoverride(self): - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) table = Table( 'override_test', meta, Column('col1', Integer, primary_key=True), @@ -421,7 +421,7 @@ class ReflectionTest(PersistTest): table.create() # clear out table registry - meta2 = BoundMetaData(testbase.db) + meta2 = MetaData(testbase.db) try: table = Table( 'override_test', meta2, diff --git a/test/ext/assignmapper.py b/test/ext/assignmapper.py index d42a809c2..650994987 100644 --- a/test/ext/assignmapper.py +++ b/test/ext/assignmapper.py @@ -9,7 +9,7 @@ from sqlalchemy.ext.sessioncontext import SessionContext class OverrideAttributesTest(PersistTest): def setUpAll(self): global metadata, table, table2 - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) table = Table('sometable', metadata, Column('id', Integer, primary_key=True), Column('data', String(30))) @@ -48,4 +48,4 @@ class OverrideAttributesTest(PersistTest): assert SomeObject.get_by(id=s.id).options[0].id == sso.id if __name__ == '__main__': - testbase.main()
\ No newline at end of file + testbase.main() diff --git a/test/ext/associationproxy.py b/test/ext/associationproxy.py index 4935f4b6e..3b18581bb 100644 --- a/test/ext/associationproxy.py +++ b/test/ext/associationproxy.py @@ -33,7 +33,7 @@ class _CollectionOperations(PersistTest): def setUp(self): collection_class = self.collection_class - metadata = BoundMetaData(db) + metadata = MetaData(db) parents_table = Table('Parent', metadata, Column('id', Integer, primary_key=True), @@ -434,7 +434,7 @@ class CustomObjectTest(_CollectionOperations): class ScalarTest(PersistTest): def test_scalar_proxy(self): - metadata = BoundMetaData(db) + metadata = MetaData(db) parents_table = Table('Parent', metadata, Column('id', Integer, primary_key=True), @@ -550,7 +550,7 @@ class ScalarTest(PersistTest): class LazyLoadTest(PersistTest): def setUp(self): - metadata = BoundMetaData(db) + metadata = MetaData(db) parents_table = Table('Parent', metadata, Column('id', Integer, primary_key=True), diff --git a/test/ext/orderinglist.py b/test/ext/orderinglist.py index 73d0405a4..6dcf057d4 100644 --- a/test/ext/orderinglist.py +++ b/test/ext/orderinglist.py @@ -52,7 +52,7 @@ class OrderingListTest(PersistTest): global metadata, slides_table, bullets_table, Slide, Bullet - metadata = BoundMetaData(db) + metadata = MetaData(db) slides_table = Table('test_Slides', metadata, Column('id', Integer, primary_key=True), Column('name', String)) diff --git a/test/ext/selectresults.py b/test/ext/selectresults.py index 8df416be9..1ec724c3d 100644 --- a/test/ext/selectresults.py +++ b/test/ext/selectresults.py @@ -13,7 +13,7 @@ class SelectResultsTest(PersistTest): def setUpAll(self): self.install_threadlocal() global foo, metadata - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) foo = Table('foo', metadata, Column('id', Integer, Sequence('foo_id_seq'), primary_key=True), Column('bar', Integer), @@ -107,7 +107,7 @@ class SelectResultsTest2(PersistTest): def setUpAll(self): self.install_threadlocal() global metadata, table1, table2 - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) table1 = Table('Table1', metadata, Column('id', Integer, primary_key=True), ) @@ -201,7 +201,7 @@ class CaseSensitiveTest(PersistTest): def setUpAll(self): self.install_threadlocal() global metadata, table1, table2 - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) table1 = Table('Table1', metadata, Column('ID', Integer, primary_key=True), ) diff --git a/test/orm/association.py b/test/orm/association.py index 755f6cf89..416cfabbb 100644 --- a/test/orm/association.py +++ b/test/orm/association.py @@ -6,7 +6,7 @@ from sqlalchemy import * class AssociationTest(testbase.PersistTest): def setUpAll(self): global items, item_keywords, keywords, metadata, Item, Keyword, KeywordAssociation - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) items = Table('items', metadata, Column('item_id', Integer, primary_key=True), Column('name', String(40)), @@ -141,7 +141,7 @@ class AssociationTest(testbase.PersistTest): class AssociationTest2(testbase.PersistTest): def setUpAll(self): global table_originals, table_people, table_isauthor, metadata, Originals, People, IsAuthor - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) table_originals = Table('Originals', metadata, Column('ID', Integer, primary_key=True), Column('Title', String(200), nullable=False), diff --git a/test/orm/cascade.py b/test/orm/cascade.py index 7cb123160..16c4db40f 100644 --- a/test/orm/cascade.py +++ b/test/orm/cascade.py @@ -185,7 +185,7 @@ class M2OCascadeTest(testbase.AssertMixin): def setUpAll(self): global ctx, data, metadata, User, Pref, Extra ctx = SessionContext(create_session) - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) extra = Table("extra", metadata, Column("extra_id", Integer, Sequence("extra_id_seq", optional=True), primary_key=True), Column("prefs_id", Integer, ForeignKey("prefs.prefs_id")) @@ -263,7 +263,7 @@ class M2OCascadeTest(testbase.AssertMixin): class M2MCascadeTest(testbase.AssertMixin): def setUpAll(self): global metadata, a, b, atob - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) a = Table('a', metadata, Column('id', Integer, primary_key=True), Column('data', String(30)) @@ -460,7 +460,7 @@ class DoubleParentOrphanTest(testbase.AssertMixin): def setUpAll(self): global metadata, address_table, businesses, homes - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) address_table = Table('addresses', metadata, Column('address_id', Integer, primary_key=True), Column('street', String(30)), diff --git a/test/orm/compile.py b/test/orm/compile.py index 96e56e597..61107ce8e 100644 --- a/test/orm/compile.py +++ b/test/orm/compile.py @@ -8,7 +8,7 @@ class CompileTest(testbase.AssertMixin): def testone(self): global metadata, order, employee, product, tax, orderproduct - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) order = Table('orders', metadata, Column('id', Integer, primary_key=True), @@ -69,7 +69,7 @@ class CompileTest(testbase.AssertMixin): def testtwo(self): """test that conflicting backrefs raises an exception""" global metadata, order, employee, product, tax, orderproduct - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) order = Table('orders', metadata, Column('id', Integer, primary_key=True), @@ -118,7 +118,7 @@ class CompileTest(testbase.AssertMixin): assert str(e).index("Backrefs do not match") > -1 def testthree(self): - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) node_table = Table("node", metadata, Column('node_id', Integer, primary_key=True), Column('name_index', Integer, nullable=True), diff --git a/test/orm/cycles.py b/test/orm/cycles.py index d02a8c8d2..c53e9e846 100644 --- a/test/orm/cycles.py +++ b/test/orm/cycles.py @@ -26,7 +26,7 @@ class SelfReferentialTest(AssertMixin): """tests a self-referential mapper, with an additional list of child objects.""" def setUpAll(self): global t1, t2, metadata - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) t1 = Table('t1', metadata, Column('c1', Integer, Sequence('t1c1_id_seq', optional=True), primary_key=True), Column('parent_c1', Integer, ForeignKey('t1.c1')), @@ -128,7 +128,7 @@ class SelfReferentialNoPKTest(AssertMixin): """test self-referential relationship that joins on a column other than the primary key column""" def setUpAll(self): global table, meta - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) table = Table('item', meta, Column('id', Integer, primary_key=True), Column('uuid', String(32), unique=True, nullable=False), @@ -173,7 +173,7 @@ class SelfReferentialNoPKTest(AssertMixin): class InheritTestOne(AssertMixin): def setUpAll(self): global parent, child1, child2, meta - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) parent = Table("parent", meta, Column("id", Integer, primary_key=True), Column("parent_data", String(50)), @@ -375,7 +375,7 @@ class BiDirectionalOneToManyTest(AssertMixin): """tests two mappers with a one-to-many relation to each other.""" def setUpAll(self): global t1, t2, metadata - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) t1 = Table('t1', metadata, Column('c1', Integer, Sequence('t1c1_id_seq', optional=True), primary_key=True), Column('c2', Integer, ForeignKey('t2.c1')) @@ -416,7 +416,7 @@ class BiDirectionalOneToManyTest2(AssertMixin): """tests two mappers with a one-to-many relation to each other, with a second one-to-many on one of the mappers""" def setUpAll(self): global t1, t2, t3, metadata - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) t1 = Table('t1', metadata, Column('c1', Integer, Sequence('t1c1_id_seq', optional=True), primary_key=True), Column('c2', Integer, ForeignKey('t2.c1')), @@ -478,7 +478,7 @@ class OneToManyManyToOneTest(AssertMixin): raise an exception when dependencies are sorted.""" def setUpAll(self): global metadata - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) global person global ball ball = Table('ball', metadata, @@ -770,7 +770,7 @@ class SelfReferentialPostUpdateTest(AssertMixin): """test using post_update on a single self-referential mapper""" def setUpAll(self): global metadata, node_table - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) node_table = Table('node', metadata, Column('id', Integer, Sequence('nodeid_id_seq', optional=True), primary_key=True), Column('path', String(50), nullable=False), @@ -873,7 +873,7 @@ class SelfReferentialPostUpdateTest(AssertMixin): class SelfReferentialPostUpdateTest2(AssertMixin): def setUpAll(self): global metadata, a_table - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) a_table = Table("a", metadata, Column("id", Integer(), primary_key=True), Column("fui", String()), diff --git a/test/orm/eagertest2.py b/test/orm/eagertest2.py index ef385df16..04de56f01 100644 --- a/test/orm/eagertest2.py +++ b/test/orm/eagertest2.py @@ -9,7 +9,7 @@ class EagerTest(AssertMixin): def setUpAll(self): global companies_table, addresses_table, invoice_table, phones_table, items_table, ctx, metadata - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) ctx = SessionContext(create_session) companies_table = Table('companies', metadata, diff --git a/test/orm/eagertest3.py b/test/orm/eagertest3.py index c92444dd6..a731581d5 100644 --- a/test/orm/eagertest3.py +++ b/test/orm/eagertest3.py @@ -7,7 +7,7 @@ import random class EagerTest(AssertMixin): def setUpAll(self): global dbmeta, owners, categories, tests, options, Owner, Category, Test, Option, false - dbmeta = BoundMetaData(testbase.db) + dbmeta = MetaData(testbase.db) # determine a literal value for "false" based on the dialect false = Boolean().dialect_impl(testbase.db.dialect).convert_bind_param(False, testbase.db.dialect) @@ -149,7 +149,7 @@ class EagerTest(AssertMixin): class EagerTest2(AssertMixin): def setUpAll(self): global metadata, middle, left, right - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) middle = Table('middle', metadata, Column('id', Integer, primary_key = True), Column('data', String(50)), diff --git a/test/orm/entity.py b/test/orm/entity.py index 202964a69..86486cafc 100644 --- a/test/orm/entity.py +++ b/test/orm/entity.py @@ -12,7 +12,7 @@ class EntityTest(AssertMixin): to have multiple primary mappers """ def setUpAll(self): global user1, user2, address1, address2, metadata, ctx - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) ctx = SessionContext(create_session) user1 = Table('user1', metadata, diff --git a/test/orm/generative.py b/test/orm/generative.py index 11daf6348..75280deed 100644 --- a/test/orm/generative.py +++ b/test/orm/generative.py @@ -12,7 +12,7 @@ class GenerativeQueryTest(PersistTest): def setUpAll(self): self.install_threadlocal() global foo, metadata - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) foo = Table('foo', metadata, Column('id', Integer, Sequence('foo_id_seq'), primary_key=True), Column('bar', Integer), @@ -111,7 +111,7 @@ class GenerativeTest2(PersistTest): def setUpAll(self): self.install_threadlocal() global metadata, table1, table2 - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) table1 = Table('Table1', metadata, Column('id', Integer, primary_key=True), ) @@ -205,7 +205,7 @@ class CaseSensitiveTest(PersistTest): def setUpAll(self): self.install_threadlocal() global metadata, table1, table2 - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) table1 = Table('Table1', metadata, Column('ID', Integer, primary_key=True), ) diff --git a/test/orm/inheritance5.py b/test/orm/inheritance5.py index b0a905f33..cf7224fa4 100644 --- a/test/orm/inheritance5.py +++ b/test/orm/inheritance5.py @@ -593,7 +593,7 @@ class GenerativeTest(testbase.AssertMixin): # +--------------------------------------- has a ------+ global metadata, status, people, engineers, managers, cars - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) # table definitions status = Table('status', metadata, Column('status_id', Integer, primary_key=True), diff --git a/test/orm/lazytest1.py b/test/orm/lazytest1.py index 9f2d53e9d..2cabac3a2 100644 --- a/test/orm/lazytest1.py +++ b/test/orm/lazytest1.py @@ -7,7 +7,7 @@ import datetime class LazyTest(AssertMixin): def setUpAll(self): global info_table, data_table, rel_table, metadata - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) info_table = Table('infos', metadata, Column('pk', Integer, primary_key=True), Column('info', String)) diff --git a/test/orm/mapper.py b/test/orm/mapper.py index 88b474e24..63af53b96 100644 --- a/test/orm/mapper.py +++ b/test/orm/mapper.py @@ -38,7 +38,7 @@ class MapperTest(MapperSuperTest): def testunicodeget(self): """test that Query.get properly sets up the type for the bind parameter. using unicode would normally fail on postgres, mysql and oracle unless it is converted to an encoded string""" - metadata = BoundMetaData(db) + metadata = MetaData(db) table = Table('foo', metadata, Column('id', Unicode(10), primary_key=True), Column('data', Unicode(40))) diff --git a/test/orm/memusage.py b/test/orm/memusage.py index b456a1abb..4e961a6d7 100644 --- a/test/orm/memusage.py +++ b/test/orm/memusage.py @@ -33,7 +33,7 @@ class MapperCleanoutTest(testbase.AssertMixin): assert True def do_test(self): - metadata = BoundMetaData(engine) + metadata = MetaData(engine) table1 = Table("mytable", metadata, Column('col1', Integer, primary_key=True), diff --git a/test/orm/onetoone.py b/test/orm/onetoone.py index 525c8db7e..6ac7c514d 100644 --- a/test/orm/onetoone.py +++ b/test/orm/onetoone.py @@ -25,7 +25,7 @@ class Port(object): class O2OTest(testbase.AssertMixin): def setUpAll(self): global jack, port, metadata, ctx - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) ctx = SessionContext(create_session) jack = Table('jack', metadata, Column('id', Integer, primary_key=True), diff --git a/test/orm/relationships.py b/test/orm/relationships.py index 5f53af080..6f652e692 100644 --- a/test/orm/relationships.py +++ b/test/orm/relationships.py @@ -2,7 +2,6 @@ import testbase import unittest, sys, datetime db = testbase.db -#db. from sqlalchemy import * @@ -106,7 +105,7 @@ class RelationTest2(testbase.PersistTest): is 'joined to itself'.""" def setUpAll(self): global metadata, company_tbl, employee_tbl - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) company_tbl = Table('company', metadata, Column('company_id', Integer, primary_key=True), @@ -221,7 +220,7 @@ class RelationTest3(testbase.PersistTest): def setUpAll(self): global jobs, pageversions, pages, metadata, Job, Page, PageVersion, PageComment import datetime - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) jobs = Table("jobs", metadata, Column("jobno", Unicode(15), primary_key=True), Column("created", DateTime, nullable=False, default=datetime.datetime.now), diff --git a/test/orm/single.py b/test/orm/single.py index d78084fe1..31a90da21 100644 --- a/test/orm/single.py +++ b/test/orm/single.py @@ -3,7 +3,7 @@ import testbase class SingleInheritanceTest(testbase.AssertMixin): def setUpAll(self): - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) global employees_table employees_table = Table('employees', metadata, Column('employee_id', Integer, primary_key=True), @@ -60,4 +60,4 @@ class SingleInheritanceTest(testbase.AssertMixin): assert session.query(JuniorEngineer).select() == [e2] if __name__ == '__main__': - testbase.main()
\ No newline at end of file + testbase.main() diff --git a/test/orm/unitofwork.py b/test/orm/unitofwork.py index bf40a49f7..6ba3f8c4b 100644 --- a/test/orm/unitofwork.py +++ b/test/orm/unitofwork.py @@ -164,7 +164,7 @@ class UnicodeTest(UnitOfWorkTest): def setUpAll(self): UnitOfWorkTest.setUpAll(self) global metadata, uni_table, uni_table2 - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) uni_table = Table('uni_test', metadata, Column('id', Integer, Sequence("uni_test_id_seq", optional=True), primary_key=True), Column('txt', Unicode(50), unique=True)) @@ -215,7 +215,7 @@ class MutableTypesTest(UnitOfWorkTest): def setUpAll(self): UnitOfWorkTest.setUpAll(self) global metadata, table - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) table = Table('mutabletest', metadata, Column('id', Integer, Sequence('mutableidseq', optional=True), primary_key=True), Column('data', PickleType), @@ -421,7 +421,7 @@ class ForeignPKTest(UnitOfWorkTest): def setUpAll(self): UnitOfWorkTest.setUpAll(self) global metadata, people, peoplesites - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) people = Table("people", metadata, Column('person', String(10), primary_key=True), Column('firstname', String(10)), @@ -462,7 +462,7 @@ class PassiveDeletesTest(UnitOfWorkTest): def setUpAll(self): UnitOfWorkTest.setUpAll(self) global metadata, mytable,myothertable - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) mytable = Table('mytable', metadata, Column('id', Integer, primary_key=True), Column('data', String(30)), @@ -1427,7 +1427,7 @@ class SaveTest2(UnitOfWorkTest): ctx.current.clear() clear_mappers() global meta, users, addresses - meta = BoundMetaData(db) + meta = MetaData(db) users = Table('users', meta, Column('user_id', Integer, Sequence('user_id_seq', optional=True), primary_key = True), Column('user_name', String(20)), diff --git a/test/perf/cascade_speed.py b/test/perf/cascade_speed.py index a09e9dd6f..d2e741442 100644 --- a/test/perf/cascade_speed.py +++ b/test/perf/cascade_speed.py @@ -1,8 +1,9 @@ +import testbase from sqlalchemy import * from timeit import Timer import sys -meta = DynamicMetaData("time_trial") +meta = MetaData() orders = Table('orders', meta, Column('id', Integer, Sequence('order_id_seq'), primary_key = True), @@ -87,4 +88,4 @@ if __name__ == "__main__": print "\nCreate backward associations" create_it = tt.create_back_assoc - tt.run(10)
\ No newline at end of file + tt.run(10) diff --git a/test/perf/masseagerload.py b/test/perf/masseagerload.py index d4076f5ba..9d77fed54 100644 --- a/test/perf/masseagerload.py +++ b/test/perf/masseagerload.py @@ -16,7 +16,7 @@ DIVISOR = 50 class LoadTest(AssertMixin): def setUpAll(self): global items, meta,subitems - meta = BoundMetaData(db) + meta = MetaData(db) items = Table('items', meta, Column('item_id', Integer, primary_key=True), Column('value', String(100))) diff --git a/test/perf/massload.py b/test/perf/massload.py index 9cbabea17..3530e4a65 100644 --- a/test/perf/massload.py +++ b/test/perf/massload.py @@ -20,7 +20,7 @@ for best results, dont run with sqlite :memory: database, and keep an eye on top class LoadTest(AssertMixin): def setUpAll(self): global items, meta - meta = BoundMetaData(db) + meta = MetaData(db) items = Table('items', meta, Column('item_id', Integer, primary_key=True), Column('value', String(100))) diff --git a/test/perf/masssave.py b/test/perf/masssave.py index 8e4d5e3ff..5690eac3f 100644 --- a/test/perf/masssave.py +++ b/test/perf/masssave.py @@ -14,7 +14,7 @@ NUM = 250000 class SaveTest(AssertMixin): def setUpAll(self): global items, metadata - metadata = BoundMetaData(db) + metadata = MetaData(db) items = Table('items', metadata, Column('item_id', Integer, primary_key=True), Column('value', String(100))) diff --git a/test/perf/poolload.py b/test/perf/poolload.py index 1b130f568..090827709 100644 --- a/test/perf/poolload.py +++ b/test/perf/poolload.py @@ -10,7 +10,7 @@ psycopg = pool.manage(psycopg,pool_size=2,max_overflow=1, timeout=5, echo=True) print psycopg db = create_engine('postgres://scott:tiger@127.0.0.1/test',pool=psycopg,strategy='threadlocal') print db.connection_provider._pool -metadata = BoundMetaData(db) +metadata = MetaData(db) users_table = Table('users', metadata, Column('user_id', Integer, primary_key=True), @@ -33,4 +33,4 @@ for x in range(0,50): thread.start_new_thread(run, ()) while True: - time.sleep(5)
\ No newline at end of file + time.sleep(5) diff --git a/test/perf/threaded_compile.py b/test/perf/threaded_compile.py index 4c9723b43..eb9e2f669 100644 --- a/test/perf/threaded_compile.py +++ b/test/perf/threaded_compile.py @@ -6,7 +6,7 @@ from sqlalchemy import * import thread, time from sqlalchemy.orm import mapperlib -meta = BoundMetaData('sqlite:///foo.db') +meta = MetaData('sqlite:///foo.db') t1 = Table('t1', meta, Column('c1', Integer, primary_key=True), diff --git a/test/perf/wsgi.py b/test/perf/wsgi.py index 7068de1fd..365956dc7 100644 --- a/test/perf/wsgi.py +++ b/test/perf/wsgi.py @@ -10,10 +10,10 @@ logging.basicConfig() logging.getLogger('sqlalchemy.pool').setLevel(logging.INFO) threadids = set() -#meta = BoundMetaData('postgres://scott:tiger@127.0.0.1/test') +#meta = MetaData('postgres://scott:tiger@127.0.0.1/test') -#meta = BoundMetaData('mysql://scott:tiger@localhost/test', poolclass=pool.SingletonThreadPool) -meta = BoundMetaData('mysql://scott:tiger@localhost/test') +#meta = MetaData('mysql://scott:tiger@localhost/test', poolclass=pool.SingletonThreadPool) +meta = MetaData('mysql://scott:tiger@localhost/test') foo = Table('foo', meta, Column('id', Integer, primary_key=True), Column('data', String(30))) diff --git a/test/sql/constraints.py b/test/sql/constraints.py index d695e824c..7e1172850 100644 --- a/test/sql/constraints.py +++ b/test/sql/constraints.py @@ -6,7 +6,7 @@ class ConstraintTest(testbase.AssertMixin): def setUp(self): global metadata - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) def tearDown(self): metadata.drop_all() diff --git a/test/sql/defaults.py b/test/sql/defaults.py index 0bc1a6b2e..331fac429 100644 --- a/test/sql/defaults.py +++ b/test/sql/defaults.py @@ -127,7 +127,7 @@ class DefaultTest(PersistTest): class AutoIncrementTest(PersistTest): @testbase.supported('postgres', 'mysql') def testnonautoincrement(self): - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) nonai_table = Table("aitest", meta, Column('id', Integer, autoincrement=False, primary_key=True), Column('data', String(20))) @@ -147,7 +147,7 @@ class AutoIncrementTest(PersistTest): nonai_table.drop() def testwithautoincrement(self): - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) table = Table("aitest", meta, Column('id', Integer, primary_key=True), Column('data', String(20))) @@ -159,7 +159,7 @@ class AutoIncrementTest(PersistTest): table.drop() def testfetchid(self): - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) table = Table("aitest", meta, Column('id', Integer, primary_key=True), Column('data', String(20))) @@ -167,7 +167,7 @@ class AutoIncrementTest(PersistTest): try: # simulate working on a table that doesn't already exist - meta2 = BoundMetaData(testbase.db) + meta2 = MetaData(testbase.db) table2 = Table("aitest", meta2, Column('id', Integer, primary_key=True), Column('data', String(20))) @@ -189,7 +189,7 @@ class SequenceTest(PersistTest): @testbase.supported('postgres', 'oracle') def setUpAll(self): global cartitems, sometable, metadata - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) cartitems = Table("cartitems", metadata, Column("cart_id", Integer, Sequence('cart_id_seq'), primary_key=True), Column("description", String(40)), diff --git a/test/sql/query.py b/test/sql/query.py index 2fe5715c2..bf7817770 100644 --- a/test/sql/query.py +++ b/test/sql/query.py @@ -13,7 +13,7 @@ class QueryTest(PersistTest): def setUpAll(self): global users, addresses, metadata - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) users = Table('query_users', metadata, Column('user_id', INT, primary_key = True), Column('user_name', VARCHAR(20)), @@ -301,7 +301,7 @@ class QueryTest(PersistTest): def test_update_functions(self): """test sending functions and SQL expressions to the VALUES and SET clauses of INSERT/UPDATE instances, and that column-level defaults get overridden""" - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) t = Table('t1', meta, Column('id', Integer, Sequence('t1idseq', optional=True), primary_key=True), Column('value', Integer) @@ -383,7 +383,7 @@ class QueryTest(PersistTest): @testbase.unsupported('oracle', 'firebird') def test_column_accessor_shadow(self): - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) shadowed = Table('test_shadowed', meta, Column('shadow_id', INT, primary_key = True), Column('shadow_name', VARCHAR(20)), @@ -413,7 +413,7 @@ class QueryTest(PersistTest): @testbase.supported('mssql') def test_fetchid_trigger(self): - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) t1 = Table('t1', meta, Column('id', Integer, Sequence('fred', 100, 1), primary_key=True), Column('descr', String(200))) @@ -439,7 +439,7 @@ class QueryTest(PersistTest): @testbase.supported('mssql') def test_insertid_schema(self): - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) con = testbase.db.connect() con.execute('create schema paj') tbl = Table('test', meta, Column('id', Integer, primary_key=True), schema='paj') @@ -505,7 +505,7 @@ class CompoundTest(PersistTest): different databases.""" def setUpAll(self): global metadata, t1, t2, t3 - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) t1 = Table('t1', metadata, Column('col1', Integer, Sequence('t1pkseq'), primary_key=True), Column('col2', String(30)), @@ -619,7 +619,7 @@ class CompoundTest(PersistTest): class OperatorTest(PersistTest): def setUpAll(self): global metadata, flds - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) flds = Table('flds', metadata, Column('idcol', Integer, Sequence('t1pkseq'), primary_key=True), Column('intcol', Integer), diff --git a/test/sql/quote.py b/test/sql/quote.py index 5259437fc..bc40d52ee 100644 --- a/test/sql/quote.py +++ b/test/sql/quote.py @@ -8,7 +8,7 @@ class QuoteTest(PersistTest): # such as: spaces, quote characters, punctuation characters, set up tests for those as # well. global table1, table2, table3 - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) table1 = Table('WorstCase1', metadata, Column('lowercase', Integer, primary_key=True), Column('UPPERCASE', Integer), @@ -46,7 +46,7 @@ class QuoteTest(PersistTest): assert(res2==[(1,2,3),(2,2,3),(4,3,2)]) def testreflect(self): - meta2 = BoundMetaData(testbase.db) + meta2 = MetaData(testbase.db) t2 = Table('WorstCase2', meta2, autoload=True, quote=True) assert t2.c.has_key('MixedCase') @@ -119,7 +119,7 @@ class QuoteTest(PersistTest): Column('MixedCase', Integer)) # first test case sensitive tables migrating via tometadata - meta = BoundMetaData(testbase.db, case_sensitive=False) + meta = MetaData(testbase.db, case_sensitive=False) lc_table1 = table1.tometadata(meta) lc_table2 = table2.tometadata(meta) assert lc_table1.case_sensitive is False diff --git a/test/sql/rowcount.py b/test/sql/rowcount.py index 95cab898c..df6a2a883 100644 --- a/test/sql/rowcount.py +++ b/test/sql/rowcount.py @@ -4,7 +4,7 @@ import testbase class FoundRowsTest(testbase.AssertMixin): """tests rowcount functionality""" def setUpAll(self): - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) global employees_table diff --git a/test/sql/testtypes.py b/test/sql/testtypes.py index c3dff5272..cf5ce1f1a 100644 --- a/test/sql/testtypes.py +++ b/test/sql/testtypes.py @@ -360,7 +360,7 @@ class DateTest(AssertMixin): class IntervalTest(AssertMixin): def setUpAll(self): global interval_table, metadata - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) interval_table = Table("intervaltable", metadata, Column("id", Integer, primary_key=True), Column("interval", Interval), @@ -378,7 +378,7 @@ class IntervalTest(AssertMixin): class BooleanTest(AssertMixin): def setUpAll(self): global bool_table - metadata = BoundMetaData(testbase.db) + metadata = MetaData(testbase.db) bool_table = Table('booltest', metadata, Column('id', Integer, primary_key=True), Column('value', Boolean)) diff --git a/test/sql/unicode.py b/test/sql/unicode.py index 65a7cce0d..7ce42bf4c 100644 --- a/test/sql/unicode.py +++ b/test/sql/unicode.py @@ -39,7 +39,7 @@ class UnicodeSchemaTest(testbase.PersistTest): t1.insert().execute({u'méil':2, u'éXXm':7}) t2.insert().execute({'a':2, 'b':2}) - meta = BoundMetaData(testbase.db) + meta = MetaData(testbase.db) tt1 = Table(t1.name, meta, autoload=True) tt2 = Table(t2.name, meta, autoload=True) tt1.insert().execute({u'méil':1, u'éXXm':5}) @@ -76,4 +76,4 @@ class UnicodeSchemaTest(testbase.PersistTest): assert new_a1.t2s[0].a == b1.a if __name__ == '__main__': - testbase.main()
\ No newline at end of file + testbase.main() diff --git a/test/tables.py b/test/tables.py index 8f00ea6ac..8e337999c 100644 --- a/test/tables.py +++ b/test/tables.py @@ -6,7 +6,7 @@ import testbase ECHO = testbase.echo db = testbase.db -metadata = BoundMetaData(db) +metadata = MetaData(db) users = Table('users', metadata, Column('user_id', Integer, Sequence('user_id_seq', optional=True), primary_key = True), diff --git a/test/testbase.py b/test/testbase.py index fab8da9e4..335a6953d 100644 --- a/test/testbase.py +++ b/test/testbase.py @@ -5,7 +5,7 @@ import sqlalchemy from sqlalchemy import sql, engine, pool import sqlalchemy.engine.base as base import optparse -from sqlalchemy.schema import BoundMetaData +from sqlalchemy.schema import MetaData from sqlalchemy.orm import clear_mappers db = None @@ -157,7 +157,7 @@ firebird=firebird://sysdba:s@localhost/tmp/test.fdb if options.log_debug is not None: for elem in options.log_debug: logging.getLogger(elem).setLevel(logging.DEBUG) - metadata = sqlalchemy.BoundMetaData(db) + metadata = sqlalchemy.MetaData(db) def unsupported(*dbs): """a decorator that marks a test as unsupported by one or more database implementations""" @@ -264,7 +264,7 @@ class ORMTest(AssertMixin): keep_data = False def setUpAll(self): global metadata - metadata = BoundMetaData(db) + metadata = MetaData(db) self.define_tables(metadata) metadata.create_all() def define_tables(self, metadata): |