Skip to content

Instantly share code, notes, and snippets.

@luhn
Created September 21, 2015 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luhn/e4972184e1e1e724a430 to your computer and use it in GitHub Desktop.
Save luhn/e4972184e1e1e724a430 to your computer and use it in GitHub Desktop.
Connection utilities for aiopg
from aiopg import Connection as BaseConnection
class Connection(BaseConnection):
async def query(self, query, args=[]):
cur = await self.cursor()
try:
await cur.execute(query, args)
return await cur.fetchall()
finally:
cur.close()
async def operation(self, query, args=[]):
cur = await self.cursor()
try:
await cur.execute(query, args)
assert cur.rowcount == -1, \
'Operation returned results.'
finally:
cur.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment