Compare commits

...

8 Commits

Author SHA1 Message Date
ac5dd5f6c9 Merge pull request 'master updates' (#28) from master into db-module
Reviewed-on: #28
2021-04-16 05:37:56 +00:00
5b2613f9be Merge pull request 'master updates' (#26) from master into db-module
Reviewed-on: #26
2021-04-16 02:08:25 +00:00
d6765e18b8 Merge pull request 'master updates' (#22) from master into db-module
Reviewed-on: #22
2021-04-09 22:06:24 +00:00
0fe7da334a Merge pull request 'master branch updates' (#19) from master into db-module
Reviewed-on: #19
2021-04-09 20:43:03 +00:00
Alex Orid
fd5f179df3 temp commit 2021-04-05 14:12:47 -04:00
Alex Orid
d80e3741d4 test stuff 2021-03-11 21:49:59 -05:00
Alex Orid
387ba00367 sqlite testing 2021-03-11 09:52:58 -05:00
Alex Orid
e4ec026a8d Update db.py 2021-03-04 17:49:17 -05:00

88
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,9 +11,75 @@ 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 = config.dbStrategy.SQLite
self.Strategy = self.Strategy_SQLite()
self.currentWorkingDB: str self.currentWorkingDB: str
self.engine = None 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.dirtyModeSetup()
def dirtyModeSetup(self):
self.create_table('testing')
self.get_data(key = "testerinoz")
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....")
command = 'CREATE TABLE ' + tableName + ' (key text, data text, bonusdata text)'
self.cursor.execute(command)
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 create_json_obj_table():
pass
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] == key:
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
def setup_engine(self, credential: credentials.DB_Credential = None): def setup_engine(self, credential: credentials.DB_Credential = None):
createEngine = True createEngine = True
if credential is None: if credential is None:
@ -26,15 +93,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'
@ -55,18 +113,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()