Skip to content

Instantly share code, notes, and snippets.

@luhn
Created October 15, 2014 19:32
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/9641a234216eb96dde68 to your computer and use it in GitHub Desktop.
Save luhn/9641a234216eb96dde68 to your computer and use it in GitHub Desktop.
Psycopg2 Connection extension
import psycopg2.extensions
class Connection(psycopg2.extensions.connection):
"""
An extension of Psycopg's connection class, to give us some additional
utilties.
"""
def query(self, query, args=tuple()):
"""
Run a query and return the full result set.
"""
with self.cursor() as c:
c.execute(query, args)
return c.fetchall()
def operation(self, query, args=tuple()):
"""
Run a query, return nothing.
"""
with self.cursor() as c:
c.execute(query, args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment