sqlite testing

This commit is contained in:
Alex Orid 2021-03-11 09:52:58 -05:00
parent e4ec026a8d
commit 387ba00367

75
db.py
View File

@ -3,6 +3,7 @@ import credentials
import config as config import config as config
import pandas as pd import pandas as pd
import sqlite3
from sqlalchemy import create_engine from sqlalchemy import create_engine
@ -10,15 +11,64 @@ class db_module():
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.dbCredential: credentials.DB_Credential self.dbCredential: credentials.DB_Credential
self.currentDBStrategy: config.DBStrategy self.currentDBStrategy: config.DBStrategy = config.dbStrategy.SQLite
self.Strategy = None self.Strategy = self.Strategy_SQLite()
self.currentWorkingDB: str self.currentWorkingDB: str
self.engine = None self.engine = None
class Strategy_SQLite(): class Strategy_SQLite():
def __init__(self): 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 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(): class Strategy_MySQL():
def __init__(self): def __init__(self):
pass pass
@ -36,15 +86,6 @@ class db_module():
self.currentWorkingDB = credential.databaseName self.currentWorkingDB = credential.databaseName
print("SQL Engine Created") 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. # 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 = ""): # def get_data_old(self, tableName: str = "", key: str = ""):
# table = '_channel_commands' # table = '_channel_commands'
@ -65,18 +106,6 @@ class db_module():
# output = "$$None$$" # output = "$$None$$"
# return output # 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__": if __name__ == "__main__":
testModule = db_module() testModule = db_module()