change that GameplayDatabase can have different backends, sqlite and postgresql with a Template example backend

This commit is contained in:
2026-04-08 14:28:39 +02:00
parent a62501cf22
commit 341bb27278
10 changed files with 1660 additions and 708 deletions
+2 -2
View File
@@ -3,7 +3,7 @@ import unittest
from pathlib import Path
import tempfile, sqlite3
from server.database import GameplayDatabase
from server.database import GameplayDatabase, GameplayBackendBuilder
class TestGameplayDatabase(unittest.IsolatedAsyncioTestCase):
def _build_state(self, turn:int, me_head:tuple[int, int], enemy_head:tuple[int, int], include_enemy:bool=True) -> dict:
@@ -57,7 +57,7 @@ class TestGameplayDatabase(unittest.IsolatedAsyncioTestCase):
async def test_records_gameplay_with_wal_and_inferred_moves(self):
with tempfile.TemporaryDirectory() as temp_dir:
db_path = Path(temp_dir) / "gameplay.sqlite3"
database = GameplayDatabase(str(db_path), busy_timeout_ms=4000)
database = GameplayDatabase(GameplayBackendBuilder.build(db_path=str(db_path), busy_timeout_ms=4000))
await database.record_game_start(self._build_state(turn=0, me_head=(1, 1), enemy_head=(5, 5)))
await database.record_turn(