mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-11-07 13:02:17 +00:00
wip: database object
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
from .conn import Database
|
||||||
from .init_checker import DatabaseInitCheckResult, check_db_init
|
from .init_checker import DatabaseInitCheckResult, check_db_init
|
||||||
from .utils import create_engine, db_path_to_sqlite_url, sqlite_url_to_db_path
|
from .utils import create_engine, db_path_to_sqlite_url, sqlite_url_to_db_path
|
||||||
|
|
||||||
@ -5,6 +6,7 @@ __all__ = [
|
|||||||
"check_db_init",
|
"check_db_init",
|
||||||
"create_engine",
|
"create_engine",
|
||||||
"db_path_to_sqlite_url",
|
"db_path_to_sqlite_url",
|
||||||
|
"Database",
|
||||||
"DatabaseInitCheckResult",
|
"DatabaseInitCheckResult",
|
||||||
"sqlite_url_to_db_path",
|
"sqlite_url_to_db_path",
|
||||||
]
|
]
|
||||||
|
|||||||
29
core/database/conn.py
Normal file
29
core/database/conn.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from sqlalchemy import text
|
||||||
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
|
from core.settings import SettingsKeys, settings
|
||||||
|
|
||||||
|
from .utils import create_engine, db_path_to_sqlite_url
|
||||||
|
|
||||||
|
|
||||||
|
class Database:
|
||||||
|
def __init__(self):
|
||||||
|
if settings.stringValue(SettingsKeys.General.DatabaseType) != "file":
|
||||||
|
raise ValueError("DatabaseType is not file")
|
||||||
|
|
||||||
|
db_path = settings.stringValue(SettingsKeys.General.DatabaseConn)
|
||||||
|
if not db_path:
|
||||||
|
raise ValueError("DatabaseConn is empty")
|
||||||
|
|
||||||
|
self.engine = create_engine(db_path_to_sqlite_url(Path(db_path)))
|
||||||
|
self.sessionmaker = sessionmaker(bind=self.engine)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def b30(self) -> float | None:
|
||||||
|
with self.sessionmaker() as session:
|
||||||
|
result = session.execute(
|
||||||
|
text("SELECT b30 FROM calculated_potential")
|
||||||
|
).fetchone()
|
||||||
|
return result[0] if result else None
|
||||||
Reference in New Issue
Block a user