diff options
author | Amjith Ramanujam <amjith@newrelic.com> | 2014-12-11 17:13:01 -0800 |
---|---|---|
committer | Amjith Ramanujam <amjith@newrelic.com> | 2014-12-11 17:13:01 -0800 |
commit | 620bf268373041628dd4fcc75087091a3eb06d3d (patch) | |
tree | 81316c2298b38ebe41d2e9f8721de22da7c03e2c /pgcli/pgexecute.py | |
parent | 51978677c94b585865e3d32a276482d3ff8f7b82 (diff) |
Add a method to get the list of databases.
Diffstat (limited to 'pgcli/pgexecute.py')
-rw-r--r-- | pgcli/pgexecute.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/pgcli/pgexecute.py b/pgcli/pgexecute.py index f07ffb24..e24741ba 100644 --- a/pgcli/pgexecute.py +++ b/pgcli/pgexecute.py @@ -12,6 +12,8 @@ class PGExecute(object): columns_query = '''SELECT column_name FROM information_schema.columns WHERE table_name =%s;''' + databases_query = '''SELECT datname FROM pg_database;''' + def __init__(self, database, user, password, host, port): self.conn = psycopg2.connect(database=database, user=user, password=password, host=host, port=port) @@ -79,3 +81,16 @@ class PGExecute(object): for table in self.tables(): columns.update(self.columns(table)) return columns + + def databases(self): + with self.conn.cursor() as cur: + cur.execute(self.databases_query) + return [x[0] for x in cur.fetchall()] + + #def _meta_execute(self, sql, query_params=()): + #with self.conn.cursor() as cur: + #if query_params: + #cur.execute(sql, query_params) + #else: + #cur.execute(sql) + #return [x[0] for x in cur.fetchall()] |