raise error on invalid database backend

This commit is contained in:
Izalia Mae 2025-04-19 11:09:26 -04:00
parent 5870f3a96b
commit 6e5f0f237a

View file

@ -30,10 +30,11 @@ def get_database(state: State, migrate: bool = True) -> Database[Connection]:
db: Database[Connection] db: Database[Connection]
if state.config.db_type == "sqlite": match state.config.db_type:
case "sqlite" | "sqlite3":
db = Database.sqlite(state.config.sqlite_path, **options) db = Database.sqlite(state.config.sqlite_path, **options)
elif state.config.db_type == "postgres": case "postgres" | "postgresql":
db = Database.postgresql( db = Database.postgresql(
state.config.pg_name, state.config.pg_name,
state.config.pg_host, state.config.pg_host,
@ -43,6 +44,9 @@ def get_database(state: State, migrate: bool = True) -> Database[Connection]:
**options **options
) )
case _:
raise RuntimeError(f"Invalid database backend: {state.config.db_type}")
db.load_prepared_statements(File.from_resource("relay", "data/statements.sql")) db.load_prepared_statements(File.from_resource("relay", "data/statements.sql"))
db.connect() db.connect()