A number of database related additions
This commit is contained in:
parent
16dc75a57d
commit
88338b0d2f
6
config.json
Normal file
6
config.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"database": {
|
||||||
|
"type": "SQLite",
|
||||||
|
"name": "scdb.db"
|
||||||
|
}
|
||||||
|
}
|
||||||
47
sc_database_generator.py
Normal file
47
sc_database_generator.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import json
|
||||||
|
from utilities.database.sqlite import SQLite
|
||||||
|
|
||||||
|
with open("config.json", 'r') as config_file:
|
||||||
|
config_json = json.load(config_file.read())
|
||||||
|
|
||||||
|
my_db = SQLite(config_json["database"]["name"])
|
||||||
|
|
||||||
|
my_db.query("""
|
||||||
|
CREATE TABLE IF NOT EXISTS media (
|
||||||
|
media_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
media_name TEXT NOT NULL,
|
||||||
|
media_uri TEXT,
|
||||||
|
media_preparing INTEGER DEFAULT 0 CHECK(media_preparing IN (0, 1)),
|
||||||
|
media_active INTEGER DEFAULT 0 CHECK(media_active IN (0, 1))
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
my_db.query("""
|
||||||
|
CREATE TABLE IF NOT EXISTS media_preparation (
|
||||||
|
media_preparation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
media_id INTEGER NOT NULL,
|
||||||
|
media_preparation_started INTEGER DEFAULT 0 CHECK(media_preparation_started IN (0, 1)),
|
||||||
|
media_preparation_finished INTEGER DEFAULT 0 CHECK(media_preparation_finished IN (0, 1)),
|
||||||
|
media_preparation_time_between_components INTEGER
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
my_db.query("""
|
||||||
|
CREATE TABLE IF NOT EXISTS media_component (
|
||||||
|
media_component_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
media_id INTEGER NOT NULL,
|
||||||
|
media_component_uri NOT NULL,
|
||||||
|
media_component_index INTEGER CHECK(media_component_index >= 1),
|
||||||
|
media_component_deleted INTEGER DEFAULT 0 CHECK(media_component_deleted IN (0, 1))
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
my_db.query("""
|
||||||
|
CREATE TABLE IF NOT EXISTS media_playback_option (
|
||||||
|
media_playback_option_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
media_playback_option TEXT NOT NULL,
|
||||||
|
media_playback_option_weight NOT NULL CHECK(media_playback_option_weight >= 1)
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
my_db.close()
|
||||||
@ -21,6 +21,8 @@ class SQLite(Database):
|
|||||||
rows = list(cursor)
|
rows = list(cursor)
|
||||||
|
|
||||||
return (len(rows), rows)
|
return (len(rows), rows)
|
||||||
|
elif query.casefold().startswith("INSERT".casefold()):
|
||||||
|
return (cursor.lastrowid, None)
|
||||||
else:
|
else:
|
||||||
return (cursor.rowcount, None)
|
return (cursor.rowcount, None)
|
||||||
|
|
||||||
|
|||||||
15
utilities/database/tools.py
Normal file
15
utilities/database/tools.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
from flask import g
|
||||||
|
from sqlite import SQLite
|
||||||
|
import json
|
||||||
|
|
||||||
|
def get_db():
|
||||||
|
db = getattr(g, "_database", None)
|
||||||
|
|
||||||
|
if db is None:
|
||||||
|
with open('../../config.json') as config_file:
|
||||||
|
config_json = json.load(config_file.read())
|
||||||
|
|
||||||
|
if str(config_json["database"]["type"]).casefold() == "SQLite".casefold():
|
||||||
|
db = g._database = SQLite(config_json["database"]["name"])
|
||||||
|
|
||||||
|
return db
|
||||||
Loading…
Reference in New Issue
Block a user