From 242c5fd73a4e0cd285039f696d849b95750f6c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mence=20Lesn=C3=A9?= Date: Sat, 20 Jan 2024 02:52:22 +0100 Subject: [PATCH] WIP --- persistence/sqlite.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/persistence/sqlite.py b/persistence/sqlite.py index b9000464..ea9dffbc 100644 --- a/persistence/sqlite.py +++ b/persistence/sqlite.py @@ -21,7 +21,7 @@ def __init__(self, config: SqliteModel): self._config = config async def call_aget(self, call_id: UUID) -> Optional[CallModel]: - async with self.use_db() as db: + async with self._use_db() as db: cursor = await db.execute( "SELECT data FROM calls WHERE id = ?", (call_id.hex,), @@ -35,7 +35,7 @@ async def call_aget(self, call_id: UUID) -> Optional[CallModel]: return None async def call_aset(self, call: CallModel) -> None: - async with self.use_db() as db: + async with self._use_db() as db: await db.execute( "INSERT OR REPLACE INTO calls VALUES (?, ?, ?, ?)", ( @@ -48,7 +48,7 @@ async def call_aset(self, call: CallModel) -> None: await db.commit() async def call_asearch_one(self, phone_number: str) -> Optional[CallModel]: - async with self.use_db() as db: + async with self._use_db() as db: cursor = await db.execute( f"SELECT data FROM calls WHERE phone_number = ? AND DATETIME(created_at) > DATETIME('now', '-{CONFIG.workflow.conversation_timeout_hour} hours') ORDER BY DATETIME(created_at) DESC LIMIT 1", (phone_number,), @@ -63,7 +63,7 @@ async def call_asearch_one(self, phone_number: str) -> Optional[CallModel]: async def call_asearch_all(self, phone_number: str) -> Optional[List[CallModel]]: calls = [] - async with self.use_db() as db: + async with self._use_db() as db: cursor = await db.execute( f"SELECT data FROM calls WHERE phone_number = ? ORDER BY DATETIME(created_at) DESC", (phone_number,), @@ -92,7 +92,7 @@ async def _init_db(self, db: SQLiteConnection): await db.commit() @asynccontextmanager - async def use_db(self) -> AsyncGenerator[SQLiteConnection, None]: + async def _use_db(self) -> AsyncGenerator[SQLiteConnection, None]: # Create folder db_path = self._config.path first_run = False