Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_transaction_readonly_oldstyle(engine):
with (await engine) as cur:
tr = Transaction(cur, IsolationLevel.serializable, readonly=True)
await tr.begin()
resp = await cur.execute('select * from tbl where id = 22')
row = await resp.fetchone()
assert row.id == 22
assert row.name == 'read only'
await tr.commit()
async def two_commit(cur):
tr = Transaction(cur, IsolationLevel.read_committed)
await tr.begin()
await tr.commit()
await tr.commit()
async def delete_from_configuration():
""" Remove initial data from configuration table """
sql = sa.text("DELETE FROM foglamp.configuration WHERE key IN {}".format(_KEYS))
async with aiopg.sa.create_engine(_CONNECTION_STRING) as engine:
async with engine.acquire() as conn:
await conn.execute(sql)
async def init_db(pg_dsn, *, loop):
db_name = 'test_{}'.format(uuid.uuid4().hex)
async with aiopg.sa.create_engine(pg_dsn, loop=loop) as db_engine:
async with db_engine.acquire() as conn:
await conn.execute('CREATE DATABASE {0}'.format(db_name))
return db_name
def create_pool(self, **kwargs):
pool = yield from sa.create_pool(database='aiopg',
user='aiopg',
password='passwd',
host='127.0.0.1',
loop=self.loop,
**kwargs)
with (yield from pool.cursor()) as cur:
yield from cur.execute("DROP TABLE IF EXISTS tbl")
yield from cur.execute("CREATE TABLE tbl "
"(id serial, name varchar(255))")
return pool
async def init_postgres(conf, loop):
engine = await aiopg.sa.create_engine(
database=conf['database'],
user=conf['user'],
password=conf['password'],
host=conf['host'],
port=conf['port'],
minsize=1,
maxsize=2,
loop=loop)
return engine
engine = loop.run_until_complete(init_postgres(pg_params, loop))
async def _get_connection_pool(self) -> aiopg.sa.Engine:
"""Returns a database connection pool object"""
if self._engine is None:
self._engine = await aiopg.sa.create_engine(_CONNECTION_STRING)
return self._engine
async def _get_connection_pool(self) -> aiopg.sa.Engine:
"""Returns a database connection pool object"""
if self._engine is None:
self._engine = await aiopg.sa.create_engine(_CONNECTION_STRING)
return self._engine
def _get_conn_and_tracer(self):
conn = self._conn = yield from aiopg.connect(**POSTGRES_CONFIG)
Pin.get_from(conn).clone(tracer=self.tracer).onto(conn)
return conn, self.tracer
async def start_firing(number):
async with aiopg.connect(loop=loop, **pg_kwargs) as connection:
async with connection.cursor(cursor_factory=cursor_factory) as cursor:
bus = await transactional_bus_factory()
await bus.client.register_api_async(dummy_api)
for x in range(0, 50):
async with lightbus_set_database(bus, connection, apis=["my.dummy"]):
await bus.my.dummy.my_event.fire_async(field="a")
await cursor.execute(
"INSERT INTO test_table VALUES (%s)", [f"{number}-{x}"]
)
await bus.client.close_async()