From 0d1d3c9506d73b40e6415800b2ae19f285912719 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Sat, 22 Aug 2020 12:32:22 -0700 Subject: [PATCH] adding simple db class for db operations --- wowstash/library/db.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 wowstash/library/db.py diff --git a/wowstash/library/db.py b/wowstash/library/db.py new file mode 100644 index 0000000..e4d5d4d --- /dev/null +++ b/wowstash/library/db.py @@ -0,0 +1,22 @@ +from psycopg2 import Error as PGError +from psycopg2 import connect as PGConnect +from wowstash import config + + +class Database(object): + def __init__(self): + self.conn = PGConnect( + user=config.DB_USER, + password=config.DB_PASS, + host=config.DB_HOST, + port=config.DB_PORT, + database=config.DB_NAME + ) + + cursor = self.conn.cursor() + cursor.execute("SELECT VERSION()") + results = cursor.fetchone() + if results: + self.connected = True + else: + self.connected = False