fix: database

This commit is contained in:
starnakin 2023-06-04 12:31:08 +02:00
parent 9958c7232f
commit b9f10402ed

View File

@ -1,6 +1,12 @@
import mysql.connector
import User
def is_in(lst: list, name: str):
for i in lst:
if (i[0] == name):
return (1);
return (0);
class Database:
def __init__(self, host, port, user, password):
"""
@ -21,7 +27,7 @@ class Database:
)
self.cursor = self.mydb.cursor()
self.cursor.execute("SHOW DATABASES");
if (not "zeolak" in self.cursor):
if (not is_in(self.cursor, "zeolak")):
self.cursor.execute("CREATE DATABASE zeolak")
self.mydb = mysql.connector.connect(
host = host,
@ -34,14 +40,16 @@ class Database:
def _create_table(self, name: str, content: dict):
command: str = f"CREATE TABLE {name} ("
for item in content.keys():
command += f"{item[0]} {item[1]}, "
for key, value in content.items():
command += f"{key} {value}, "
command = command[:-2]
command += ")"
print (command)
self.cursor.execute(command)
def create_user_table(self):
self.cursor.execute("SHOW TABLES");
if (not "users" in self.cursor):
if (not is_in(self.cursor, "users")):
data = {
"email": "VARCHAR(255)",
"username": "VARCHAR(255)",