]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
completed connectable/bind_to/engine work for [ticket:645]
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 16 Jul 2007 16:23:00 +0000 (16:23 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 16 Jul 2007 16:23:00 +0000 (16:23 +0000)
lib/sqlalchemy/orm/session.py
lib/sqlalchemy/schema.py
test/engine/reflection.py
test/engine/transaction.py
test/orm/assorted_eager.py
test/orm/relationships.py
test/orm/session.py

index cd7dcc04ee4082ed206573936bc348d5923e9fde..a4e2287dede623bc7503aa42c7f4e066d8aaeab5 100644 (file)
@@ -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.
index 897f397b61bdff4400a8f0cffbfd07ecbc8f01dd..a504111a73630bab609a49ad9f1f3b071dd41792 100644 (file)
@@ -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)
index 9aa07fa4204ba244d3a96ff1e9c79f13fcf00635..75abf7ef80405c97f76dc093f3dd963986e8c592 100644 (file)
@@ -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):
index 246d5cea50157f6ae953d68fd89068132e1702e7..f86d0cbdb1c17ab97edc67457bd5ce2af8fe2104 100644 (file)
@@ -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)
index f647a5cccd7d03604068e79e489fc51a98b382fc..4187ad8def7f516af3ccfb203f97bf4aa48973aa 100644 (file)
@@ -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'))
index 80fe147275ab5ef3bb2bbaf96c56e2507eeb9176..c669e0f3cc3e565d55ab8cf4e4e4e630bfc5aadc 100644 (file)
@@ -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)
index 1d337deef655568ab56748d52ab7c6249d74ab63..e67037b0afa3f385ef1a423f78c7343e0b1d6c36 100644 (file)
@@ -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()