Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ac5dd5f6c9 | |||
| 5b2613f9be | |||
| d6765e18b8 | |||
| 0fe7da334a | |||
|
|
fd5f179df3 | ||
|
|
d80e3741d4 | ||
|
|
387ba00367 | ||
|
|
e4ec026a8d |
88
db.py
88
db.py
@ -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()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user