Skip to content

Instantly share code, notes, and snippets.

@startakovsky
Created June 25, 2015 22:48
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 startakovsky/c47469c588902d0bf814 to your computer and use it in GitHub Desktop.
Save startakovsky/c47469c588902d0bf814 to your computer and use it in GitHub Desktop.
one strategy for dealing with sql queries.... it's imperfect but that's what you wanted i think.
class PostGres(object):
connection = None
def __init__(self, connection, debug_on=True):
self.connection = connection
self.autocommit = True
self.debug_on = debug_on
def get_table_count(self, table):
sql = "select count(*) from {0}".format(table)
self.debug(sql)
cur = self.connection.cursor()
cur.execute(sql)
reserved = cur.fetchone()
cur.close()
# return data
return reserved[0]
def debug(self, s):
if self.debug_on:
print "{}".format(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment