Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Jan 20, 2024
1 parent cba5106 commit 242c5fd
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions persistence/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,),
Expand All @@ -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 (?, ?, ?, ?)",
(
Expand All @@ -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,),
Expand All @@ -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,),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 242c5fd

Please sign in to comment.