From 13d8dbb4135f290a80577f6fca09d9488e861a18 Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 31 Jul 2017 19:44:32 +0200 Subject: Factoring out DB operations --- playoff/db.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 playoff/db.py (limited to 'playoff/db.py') diff --git a/playoff/db.py b/playoff/db.py new file mode 100644 index 0000000..aa0c2e2 --- /dev/null +++ b/playoff/db.py @@ -0,0 +1,19 @@ +import mysql.connector + +class PlayoffDB(object): + + db_cursor = None + + def __init__(self, settings): + self.database = mysql.connector.connect( + user=settings['user'], + password=settings['pass'], + host=settings['host'], + port=settings['port'] + ) + self.db_cursor = self.database.cursor(buffered=True) + + def fetch(self, db, sql, params): + self.db_cursor.execute(sql.replace('#db#', db), params) + row = self.db_cursor.fetchone() + return row -- cgit v1.2.3