Move definition of db into dbmanager
This commit is contained in:
parent
9f234bb007
commit
bf89172f8a
@ -1,4 +1,6 @@
|
|||||||
# Standard library imports
|
# Standard library imports
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
# PyQt imports
|
# PyQt imports
|
||||||
|
|
||||||
@ -6,6 +8,7 @@
|
|||||||
from alchemical import Alchemical # type:ignore
|
from alchemical import Alchemical # type:ignore
|
||||||
|
|
||||||
# App imports
|
# App imports
|
||||||
|
from config import Config
|
||||||
|
|
||||||
|
|
||||||
class DatabaseManager:
|
class DatabaseManager:
|
||||||
@ -29,3 +32,12 @@ class DatabaseManager:
|
|||||||
if DatabaseManager.__instance is None:
|
if DatabaseManager.__instance is None:
|
||||||
DatabaseManager(database_url, **kwargs)
|
DatabaseManager(database_url, **kwargs)
|
||||||
return DatabaseManager.__instance
|
return DatabaseManager.__instance
|
||||||
|
|
||||||
|
|
||||||
|
# Establish database connection
|
||||||
|
DATABASE_URL = os.environ.get("DATABASE_URL")
|
||||||
|
if DATABASE_URL is None:
|
||||||
|
raise ValueError("DATABASE_URL is undefined")
|
||||||
|
if "unittest" in sys.modules and "sqlite" not in DATABASE_URL:
|
||||||
|
raise ValueError("Unit tests running on non-Sqlite database")
|
||||||
|
db = DatabaseManager.get_instance(DATABASE_URL, engine_options=Config.ENGINE_OPTIONS).db
|
||||||
|
|||||||
@ -29,9 +29,9 @@ from classes import (
|
|||||||
TrackDTO,
|
TrackDTO,
|
||||||
)
|
)
|
||||||
from config import Config
|
from config import Config
|
||||||
|
from dbmanager import db
|
||||||
from log import log, log_call
|
from log import log, log_call
|
||||||
from models import (
|
from models import (
|
||||||
db,
|
|
||||||
NoteColours,
|
NoteColours,
|
||||||
Playdates,
|
Playdates,
|
||||||
PlaylistRows,
|
PlaylistRows,
|
||||||
|
|||||||
@ -34,14 +34,6 @@ import dbtables
|
|||||||
from log import log
|
from log import log
|
||||||
|
|
||||||
|
|
||||||
# Establish database connection
|
|
||||||
DATABASE_URL = os.environ.get("DATABASE_URL")
|
|
||||||
if DATABASE_URL is None:
|
|
||||||
raise ValueError("DATABASE_URL is undefined")
|
|
||||||
if "unittest" in sys.modules and "sqlite" not in DATABASE_URL:
|
|
||||||
raise ValueError("Unit tests running on non-Sqlite database")
|
|
||||||
db = DatabaseManager.get_instance(DATABASE_URL, engine_options=Config.ENGINE_OPTIONS).db
|
|
||||||
|
|
||||||
# Configure the cache region
|
# Configure the cache region
|
||||||
cache_region = make_region().configure(
|
cache_region = make_region().configure(
|
||||||
'dogpile.cache.memory', # Use in-memory caching for now (switch to Redis if needed)
|
'dogpile.cache.memory', # Use in-memory caching for now (switch to Redis if needed)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user