26 lines
1.1 KiB
Python
26 lines
1.1 KiB
Python
from .Template import GameplayBackendTemplate
|
|
|
|
class GameplayBackendBuilder:
|
|
@staticmethod
|
|
def build(backend:str="sqlite", db_path:str|None=None, busy_timeout_ms:int=5000, pg_dsn:str|None=None, pg_min_size:int=1, pg_max_size:int=5) -> GameplayBackendTemplate:
|
|
normalized = (backend or "sqlite").strip().lower()
|
|
|
|
if normalized == "postgresql" or normalized == "postgres":
|
|
from .PostgresqlGameplayBackend import PostgresqlGameplayBackend
|
|
if not pg_dsn:
|
|
raise ValueError("pg_dsn is required for the postgresql backend")
|
|
return PostgresqlGameplayBackend(
|
|
dsn=pg_dsn,
|
|
min_size=pg_min_size,
|
|
max_size=pg_max_size,
|
|
sqlite_migration_path=db_path,
|
|
)
|
|
|
|
if normalized == "sqlite":
|
|
from .SqliteGameplayBackend import SqliteGameplayBackend
|
|
if not db_path:
|
|
raise ValueError("db_path is required for the sqlite backend")
|
|
return SqliteGameplayBackend(db_path=db_path, busy_timeout_ms=busy_timeout_ms)
|
|
|
|
raise ValueError(f"Unknown gameplay backend: {backend!r}. Choose 'sqlite' or 'postgresql'.")
|