63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
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() |