peewee-async icon indicating copy to clipboard operation
peewee-async copied to clipboard

Can we got a connection from pool and set isolation level only for this connection?

Open jiamo opened this issue 3 years ago • 1 comments

At now use different lsolation_level should do it in global.

database = PooledPostgresqlDatabase(
    **config.database_conf,
    autoconnect=True,
    autorollback=True,
    max_connections=10,
    isolation_level=ISOLATION_LEVEL_REPEATABLE_READ
)
pg_objects = Manager(database=database, loop=loop)
objects = await pg_objects.execute(q)

Can we got connection from pool and set isolation level only for this connection. After the connection done remove this connection:

async with db.pg_objects.connection() as conn:
      conn.set_isolation_level()
      .........

jiamo avatar Oct 13 '20 06:10 jiamo

This snippet should work for you.

async with db.pg_objects.pool.acquire() as conn:
      conn.set_isolation_level()

kalombos avatar Apr 08 '24 09:04 kalombos