Created
September 21, 2015 21:58
-
-
Save luhn/e4972184e1e1e724a430 to your computer and use it in GitHub Desktop.
Connection utilities for aiopg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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