How to use the aiopg.Transaction function in aiopg

To help you get started, we’ve selected a few aiopg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aio-libs / aiopg / tests / test_transaction.py View on Github external
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()
github aio-libs / aiopg / tests / test_transaction.py View on Github external
async def two_commit(cur):
    tr = Transaction(cur, IsolationLevel.read_committed)
    await tr.begin()
    await tr.commit()
    await tr.commit()
github aio-libs / aiopg / tests / test_transaction.py View on Github external
async def two_begin(cur):
    tr = Transaction(cur, IsolationLevel.read_committed)
    await tr.begin()
    await tr.begin()
github aio-libs / aiopg / tests / test_transaction.py View on Github external
async def e_savepoint(cur):
    tr = Transaction(cur, IsolationLevel.read_committed)
    await tr.savepoint()
github aio-libs / aiopg / tests / test_transaction.py View on Github external
async def two_rollback(cur):
    tr = Transaction(cur, IsolationLevel.read_committed)
    await tr.begin()
    await tr.rollback()
    await tr.rollback()
github aio-libs / aiopg / tests / test_transaction.py View on Github external
def test_transaction_value_error():
    with pytest.raises(ValueError):
        Transaction(None, IsolationLevel.read_committed, readonly=True)
github aio-libs / aiopg / tests / test_transaction.py View on Github external
async def e_rollback_savepoint(cur):
    tr = Transaction(cur, IsolationLevel.read_committed)
    await tr.rollback_savepoint()
github aio-libs / aiopg / tests / pep492 / test_async_transaction.py View on Github external
async def test_transaction_rollback(engine):
    async with engine.cursor() as cur:
        with pytest.raises(psycopg2.DataError):
            async with Transaction(cur, IsolationLevel.read_committed):
                await cur.execute("insert into tbl values(1/0, 'no data')")

        await cur.execute('select * from tbl')
        row = await cur.fetchall()
        assert row == [(22, 'read only'), ]
github aio-libs / aiopg / tests / test_transaction.py View on Github external
async def test_transaction_point_oldstyle(engine):
    with (await engine) as cur:
        tr = Transaction(cur, IsolationLevel.read_committed)
        await tr.begin()

        await cur.execute("insert into tbl values(1, 'data')")

        try:
            await tr.savepoint()
            await cur.execute("insert into tbl values(1/0, 'no data')")
        except psycopg2.DataError:
            await tr.rollback_savepoint()

        await tr.savepoint()
        await cur.execute("insert into tbl values(2, 'data')")
        await tr.release_savepoint()

        await cur.execute("insert into tbl values(3, 'data')")
github aio-libs / aiopg / tests / test_transaction.py View on Github external
async def e_release_savepoint(cur):
    tr = Transaction(cur, IsolationLevel.read_committed)
    await tr.release_savepoint()