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
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.
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.
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
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):
% (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)
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
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
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)
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):