Created
October 15, 2014 19:32
-
-
Save luhn/9641a234216eb96dde68 to your computer and use it in GitHub Desktop.
Psycopg2 Connection extension
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
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