initial build
This commit is contained in:
63
models/database.py
Normal file
63
models/database.py
Normal file
@@ -0,0 +1,63 @@
|
||||
from multiprocessing import connection
|
||||
import sqlite3
|
||||
|
||||
from models.city import City
|
||||
|
||||
class Database:
|
||||
connection: sqlite3.Connection = None
|
||||
|
||||
@staticmethod
|
||||
def init():
|
||||
# Open connection with database
|
||||
con = sqlite3.connect("./database.db")
|
||||
Database.connection = con
|
||||
|
||||
Database._init_log_table()
|
||||
Database._init_user_table()
|
||||
Database._init_city_table()
|
||||
|
||||
@staticmethod
|
||||
def _init_log_table():
|
||||
cursor = Database.connection.cursor()
|
||||
q = cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS logs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT,
|
||||
date TEXT,
|
||||
time TEXT,
|
||||
description TEXT,
|
||||
additional_information TEXT,
|
||||
suspicious BOOL
|
||||
)
|
||||
""")
|
||||
cursor.close()
|
||||
|
||||
@staticmethod
|
||||
def _init_user_table():
|
||||
cursor = Database.connection.cursor()
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY,
|
||||
firstname TEXT,
|
||||
lastname TEXT,
|
||||
address TEXT,
|
||||
zipcode TEXT,
|
||||
city_id INTEGER,
|
||||
email TEXT,
|
||||
phone TEXT,
|
||||
password TEXT,
|
||||
role TEXT
|
||||
)
|
||||
""")
|
||||
cursor.close()
|
||||
|
||||
@staticmethod
|
||||
def _init_city_table():
|
||||
cursor = Database.connection.cursor()
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS cities (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT
|
||||
)
|
||||
""")
|
||||
cursor.close()
|
Reference in New Issue
Block a user