Skip to content

Instantly share code, notes, and snippets.

@evgenii-malov
Last active January 18, 2021 22:39
Show Gist options
  • Save evgenii-malov/96d1b7873aaba0cf6ff2d45ca46f7dee to your computer and use it in GitHub Desktop.
Save evgenii-malov/96d1b7873aaba0cf6ff2d45ca46f7dee to your computer and use it in GitHub Desktop.
async def insert_one(pool, sql, params):
async with pool.acquire() as conn:
async with conn.cursor() as cur:
try:
await cur.execute(sql, params)
value = await cur.fetchone()
except Exception as e:
await conn.rollback()
raise e
else:
await conn.commit()
return cur.lastrowid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment