Created
June 25, 2015 22:48
-
-
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.
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
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