From: Mike Bayer Date: Mon, 16 Jul 2007 16:23:00 +0000 (+0000) Subject: completed connectable/bind_to/engine work for [ticket:645] X-Git-Tag: rel_0_4_6~107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f593723414786290a7040b599b905c5da01988e2;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git completed connectable/bind_to/engine work for [ticket:645] --- diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index cd7dcc04ee..a4e2287ded 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -99,13 +99,13 @@ class Session(object): of Sessions, see the ``sqlalchemy.ext.sessioncontext`` module. """ - def __init__(self, bind=None, bind_to=None, hash_key=None, import_session=None, echo_uow=False, weak_identity_map=False): + def __init__(self, bind=None, hash_key=None, import_session=None, echo_uow=False, weak_identity_map=False): if import_session is not None: self.uow = unitofwork.UnitOfWork(identity_map=import_session.uow.identity_map, weak_identity_map=weak_identity_map) else: self.uow = unitofwork.UnitOfWork(weak_identity_map=weak_identity_map) - self.bind = bind or bind_to + self.bind = bind self.binds = {} self.echo_uow = echo_uow self.weak_identity_map = weak_identity_map @@ -123,8 +123,6 @@ class Session(object): self.uow.echo = value echo_uow = property(_get_echo_uow,_set_echo_uow) - bind_to = property(lambda self:self.bind) - def create_transaction(self, **kwargs): """Return a new ``SessionTransaction`` corresponding to an existing or new transaction. diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 897f397b61..a504111a73 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -71,14 +71,6 @@ class SchemaItem(object): m = self._derived_metadata() return m and m.bind or None - def get_engine(self): - """Return the engine or raise an error if no engine. - - Deprecated. use the "bind" attribute. - """ - - return self._get_engine(raiseerr=True) - def _set_casing_strategy(self, kwargs, keyname='case_sensitive'): """Set the "case_sensitive" argument sent via keywords to the item's constructor. @@ -180,7 +172,7 @@ class Table(SchemaItem, sql.TableClause): This subclasses ``sql.TableClause`` to provide a table that is associated with an instance of ``MetaData``, which in turn - may be associated with an instance of ``SQLEngine``. + may be associated with an instance of ``Engine``. Whereas ``TableClause`` represents a table as its used in an SQL expression, ``Table`` represents a table as it exists in a @@ -356,36 +348,28 @@ class Table(SchemaItem, sql.TableClause): else: return [] - def exists(self, bind=None, connectable=None): + def exists(self, bind=None): """Return True if this table exists.""" - if connectable is not None: - bind = connectable - if bind is None: bind = self._get_engine(raiseerr=True) def do(conn): - e = conn.engine - return e.dialect.has_table(conn, self.name, schema=self.schema) + return conn.dialect.has_table(conn, self.name, schema=self.schema) return bind.run_callable(do) - def create(self, bind=None, checkfirst=False, connectable=None): + def create(self, bind=None, checkfirst=False): """Issue a ``CREATE`` statement for this table. See also ``metadata.create_all()``.""" - if connectable is not None: - bind = connectable self.metadata.create_all(bind=bind, checkfirst=checkfirst, tables=[self]) - def drop(self, bind=None, checkfirst=False, connectable=None): + def drop(self, bind=None, checkfirst=False): """Issue a ``DROP`` statement for this table. See also ``metadata.drop_all()``.""" - if connectable is not None: - bind = connectable self.metadata.drop_all(bind=bind, checkfirst=checkfirst, tables=[self]) def tometadata(self, metadata, schema=None): @@ -1051,16 +1035,16 @@ class Index(SchemaItem): % (self.name, column)) self.columns.append(column) - def create(self, connectable=None): - if connectable is not None: - connectable.create(self) + def create(self, bind=None): + if bind is not None: + bind.create(self) else: self._get_engine(raiseerr=True).create(self) return self - def drop(self, connectable=None): - if connectable is not None: - connectable.drop(self) + def drop(self, bind=None): + if bind is not None: + bind.drop(self) else: self._get_engine(raiseerr=True).drop(self) @@ -1148,7 +1132,7 @@ class MetaData(SchemaItem): def _get_parent(self): return None - def create_all(self, bind=None, tables=None, checkfirst=True, connectable=None): + def create_all(self, bind=None, tables=None, checkfirst=True): """Create all tables stored in this metadata. This will conditionally create tables depending on if they do @@ -1158,21 +1142,16 @@ class MetaData(SchemaItem): A ``Connectable`` used to access the database; if None, uses the existing bind on this ``MetaData``, if any. - connectable - deprecated. synonymous with "bind" - tables Optional list of tables, which is a subset of the total tables in the ``MetaData`` (others are ignored). """ - if connectable is not None: - bind = connectable if bind is None: bind = self._get_engine(raiseerr=True) bind.create(self, checkfirst=checkfirst, tables=tables) - def drop_all(self, bind=None, tables=None, checkfirst=True, connectable=None): + def drop_all(self, bind=None, tables=None, checkfirst=True): """Drop all tables stored in this metadata. This will conditionally drop tables depending on if they @@ -1182,16 +1161,11 @@ class MetaData(SchemaItem): A ``Connectable`` used to access the database; if None, uses the existing bind on this ``MetaData``, if any. - connectable - deprecated. synonymous with "bind" - tables Optional list of tables, which is a subset of the total tables in the ``MetaData`` (others are ignored). """ - if connectable is not None: - bind = connectable if bind is None: bind = self._get_engine(raiseerr=True) bind.drop(self, checkfirst=checkfirst, tables=tables) diff --git a/test/engine/reflection.py b/test/engine/reflection.py index 9aa07fa420..75abf7ef80 100644 --- a/test/engine/reflection.py +++ b/test/engine/reflection.py @@ -518,28 +518,28 @@ class CreateDropTest(PersistTest): def testcheckfirst(self): try: assert not users.exists(testbase.db) - users.create(connectable=testbase.db) + users.create(bind=testbase.db) assert users.exists(testbase.db) - users.create(connectable=testbase.db, checkfirst=True) - users.drop(connectable=testbase.db) - users.drop(connectable=testbase.db, checkfirst=True) - assert not users.exists(connectable=testbase.db) - users.create(connectable=testbase.db, checkfirst=True) - users.drop(connectable=testbase.db) + users.create(bind=testbase.db, checkfirst=True) + users.drop(bind=testbase.db) + users.drop(bind=testbase.db, checkfirst=True) + assert not users.exists(bind=testbase.db) + users.create(bind=testbase.db, checkfirst=True) + users.drop(bind=testbase.db) finally: - metadata.drop_all(connectable=testbase.db) + metadata.drop_all(bind=testbase.db) def test_createdrop(self): - metadata.create_all(connectable=testbase.db) + metadata.create_all(bind=testbase.db) self.assertEqual( testbase.db.has_table('items'), True ) self.assertEqual( testbase.db.has_table('email_addresses'), True ) - metadata.create_all(connectable=testbase.db) + metadata.create_all(bind=testbase.db) self.assertEqual( testbase.db.has_table('items'), True ) - metadata.drop_all(connectable=testbase.db) + metadata.drop_all(bind=testbase.db) self.assertEqual( testbase.db.has_table('items'), False ) self.assertEqual( testbase.db.has_table('email_addresses'), False ) - metadata.drop_all(connectable=testbase.db) + metadata.drop_all(bind=testbase.db) self.assertEqual( testbase.db.has_table('items'), False ) class SchemaTest(PersistTest): diff --git a/test/engine/transaction.py b/test/engine/transaction.py index 246d5cea50..f86d0cbdb1 100644 --- a/test/engine/transaction.py +++ b/test/engine/transaction.py @@ -478,7 +478,7 @@ class TLTransactionTest(testbase.PersistTest): try: mapper(User, users) - sess = create_session(bind_to=tlengine) + sess = create_session(bind=tlengine) tlengine.begin() u = User() sess.save(u) diff --git a/test/orm/assorted_eager.py b/test/orm/assorted_eager.py index f647a5cccd..4187ad8def 100644 --- a/test/orm/assorted_eager.py +++ b/test/orm/assorted_eager.py @@ -194,7 +194,7 @@ class EagerTest2(AssertMixin): 'right': relation(Right, lazy=False, backref=backref('middle', lazy=False)), } ) - session = create_session(bind_to=testbase.db) + session = create_session(bind=testbase.db) p = Middle('test1') p.left.append(Left('tag1')) p.right.append(Right('tag2')) diff --git a/test/orm/relationships.py b/test/orm/relationships.py index 80fe147275..c669e0f3cc 100644 --- a/test/orm/relationships.py +++ b/test/orm/relationships.py @@ -43,7 +43,7 @@ class RelationTest(testbase.PersistTest): ) def setUp(self): global session - session = create_session(bind_to=testbase.db) + session = create_session(bind=testbase.db) conn = session.connect() conn.create(tbl_a) conn.create(tbl_b) diff --git a/test/orm/session.py b/test/orm/session.py index 1d337deef6..e67037b0af 100644 --- a/test/orm/session.py +++ b/test/orm/session.py @@ -26,7 +26,7 @@ class SessionTest(AssertMixin): c = testbase.db.connect() class User(object):pass mapper(User, users) - s = create_session(bind_to=c) + s = create_session(bind=c) s.save(User()) s.flush() c.execute("select * from users") @@ -89,7 +89,7 @@ class SessionTest(AssertMixin): try: class User(object):pass mapper(User, users) - s = create_session(bind_to=c) + s = create_session(bind=c) tran = s.create_transaction() s.save(User()) s.flush()