Here are the examples of the python api sqlalchemy.engine.Connection taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
5 Examples
3
View Complete Implementation : conftest.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : CloverHealth
Copyright BSD 3-Clause "New" or "Revised" License
Author : CloverHealth
@pytest.yield_fixture()
def session(connection: sa.engine.Connection, sessionmaker: orm.sessionmaker): # pylint: disable=redefined-outer-name
""" yields temporalized session -- per test """
transaction = connection.begin()
sess = sessionmaker(bind=connection)
yield sess
transaction.rollback()
sess.close()
3
View Complete Implementation : test_persist_changes_on_commit.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : CloverHealth
Copyright BSD 3-Clause "New" or "Revised" License
Author : CloverHealth
@pytest.yield_fixture()
def second_session(connection: sa.engine.Connection, sessionmaker: orm.sessionmaker):
transaction = connection.begin()
sess = sessionmaker(bind=connection)
yield sess
transaction.rollback()
sess.close()
3
View Complete Implementation : test_bind.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_create_drop_constructor_bound(self):
for bind in (testing.db, testing.db.connect()):
try:
for args in (([bind], {}), ([], {"bind": bind})):
metadata = MetaData(*args[0], **args[1])
table = Table(
"test_table", metadata, Column("foo", Integer)
)
astert metadata.bind is table.bind is bind
metadata.create_all()
is_true(inspect(bind).has_table(table.name))
metadata.drop_all()
table.create()
table.drop()
is_false(inspect(bind).has_table(table.name))
finally:
if isinstance(bind, engine.Connection):
bind.close()
0
View Complete Implementation : test_bind.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
@testing.uses_deprecated()
def test_create_drop_bound(self):
for meta in (MetaData, ThreadLocalMetaData):
for bind in (testing.db, testing.db.connect()):
metadata = meta()
table = Table("test_table", metadata, Column("foo", Integer))
metadata.bind = bind
astert metadata.bind is table.bind is bind
metadata.create_all()
astert table.exists()
metadata.drop_all()
table.create()
table.drop()
astert not table.exists()
metadata = meta()
table = Table("test_table", metadata, Column("foo", Integer))
metadata.bind = bind
astert metadata.bind is table.bind is bind
metadata.create_all()
astert table.exists()
metadata.drop_all()
table.create()
table.drop()
astert not table.exists()
if isinstance(bind, engine.Connection):
bind.close()
0
View Complete Implementation : test_bind.py
Copyright MIT License
Author : sqlalchemy
Copyright MIT License
Author : sqlalchemy
def test_clauseelement(self):
metadata = MetaData()
table = Table("test_table", metadata, Column("foo", Integer))
metadata.create_all(bind=testing.db)
try:
for elem in [
table.select,
lambda **kwargs: sa.func.current_timestamp(**kwargs).select(),
# func.current_timestamp().select,
lambda **kwargs: text("select * from test_table", **kwargs),
]:
for bind in (testing.db, testing.db.connect()):
try:
e = elem(bind=bind)
astert e.bind is bind
e.execute().close()
finally:
if isinstance(bind, engine.Connection):
bind.close()
e = elem()
astert e.bind is None
astert_raises(exc.UnboundExecutionError, e.execute)
finally:
if isinstance(bind, engine.Connection):
bind.close()
metadata.drop_all(bind=testing.db)