From 387ba00367c557d9cc628a6dfdce1fa81811ea6f Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Thu, 11 Mar 2021 09:52:58 -0500 Subject: [PATCH] sqlite testing --- db.py | 75 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 23 deletions(-) diff --git a/db.py b/db.py index 23920a9..6609e71 100644 --- a/db.py +++ b/db.py @@ -3,6 +3,7 @@ import credentials import config as config import pandas as pd +import sqlite3 from sqlalchemy import create_engine @@ -10,15 +11,64 @@ class db_module(): def __init__(self): super().__init__() self.dbCredential: credentials.DB_Credential - self.currentDBStrategy: config.DBStrategy - self.Strategy = None + self.currentDBStrategy: config.DBStrategy = config.dbStrategy.SQLite + self.Strategy = self.Strategy_SQLite() self.currentWorkingDB: str self.engine = None + class Strategy_SQLite(): def __init__(self): + self.dbName:str = "" + self.connection = sqlite3.connect(":memory:") + self.cursor = self.connection.cursor() + self.dirtyMode:bool = False + self.create_table() + self.get_data() + + def setup_connection(self, newName:str): + self.dbName = newName + self.connection = sqlite3.connect(newName) + + # Table Stuff + def create_table(self, tableName: str = ""): + print("making stuff....") + self.cursor.execute("CREATE TABLE testing (key text, data text, bonusdata text)") + self.cursor.execute("INSERT INTO testing VALUES ('testing','testerino','extra stuff 1')") + self.cursor.execute("INSERT INTO testing VALUES ('testing','testerinoz','extra stuff 2')") + self.cursor.execute("INSERT INTO testing VALUES ('testing','testerinozy','extra stuff 3')") + self.connection.commit() + + def does_table_exist(self, tableName: str = ""): pass + def delete_table(self, tableName: str = ""): + pass + + # Data Stuff + def get_data(self, tableName: str = "", key: str = ""): + print("fetching...") + t = ('testing',) + self.cursor.execute('SELECT * FROM testing WHERE key=?', t) + resultz = self.cursor.fetchall() + print(resultz) + print("loop") + for thing in resultz: + if thing[1] == "testerino": + print("found it") + print(thing[2]) + + def insert_data(self, tableName: str = "", param: str = ""): + pass + + def edit_data(self, tableName: str = "", key: str = "", param: str = ""): + pass + + def delete_data(self, tableName: str = "", key: str = ""): + pass + + + class Strategy_MySQL(): def __init__(self): pass @@ -36,15 +86,6 @@ class db_module(): self.currentWorkingDB = credential.databaseName print("SQL Engine Created") - def create_table(self, tableName: str = ""): - pass - - def does_table_exist(self, tableName: str = ""): - pass - - def delete_table(self, tableName: str = ""): - pass - # This was a old function used prior to the creation of this class. I need to remake it. # def get_data_old(self, tableName: str = "", key: str = ""): # table = '_channel_commands' @@ -65,18 +106,6 @@ class db_module(): # output = "$$None$$" # return output - def get_data(self, tableName: str = "", key: str = ""): - pass - - def insert_data(self, tableName: str = "", param: str = ""): - pass - - def edit_data(self, tableName: str = "", key: str = "", param: str = ""): - pass - - def delete_data(self, tableName: str = "", key: str = ""): - pass - if __name__ == "__main__": testModule = db_module()