Fix Sqlite rows

This commit is contained in:
itqop 2025-07-12 10:37:28 +03:00
parent bf830fd330
commit 03caebfb0b
1 changed files with 8 additions and 0 deletions

View File

@ -30,6 +30,7 @@ class ArticleRepository:
) )
async with await self.db_service.get_connection() as conn: async with await self.db_service.get_connection() as conn:
conn.row_factory = aiosqlite.Row
cursor = await conn.execute( cursor = await conn.execute(
""" """
INSERT INTO articles (url, title, raw_text, status, created_at) INSERT INTO articles (url, title, raw_text, status, created_at)
@ -52,6 +53,7 @@ class ArticleRepository:
async def get_by_id(self, article_id: int) -> ArticleDTO | None: async def get_by_id(self, article_id: int) -> ArticleDTO | None:
async with await self.db_service.get_connection() as conn: async with await self.db_service.get_connection() as conn:
conn.row_factory = aiosqlite.Row
cursor = await conn.execute( cursor = await conn.execute(
"SELECT * FROM articles WHERE id = ?", "SELECT * FROM articles WHERE id = ?",
(article_id,), (article_id,),
@ -65,6 +67,7 @@ class ArticleRepository:
async def get_by_url(self, url: str) -> ArticleDTO | None: async def get_by_url(self, url: str) -> ArticleDTO | None:
async with await self.db_service.get_connection() as conn: async with await self.db_service.get_connection() as conn:
conn.row_factory = aiosqlite.Row
cursor = await conn.execute( cursor = await conn.execute(
"SELECT * FROM articles WHERE url = ?", "SELECT * FROM articles WHERE url = ?",
(url,), (url,),
@ -83,6 +86,7 @@ class ArticleRepository:
article.updated_at = datetime.now(timezone.utc) article.updated_at = datetime.now(timezone.utc)
async with await self.db_service.get_connection() as conn: async with await self.db_service.get_connection() as conn:
conn.row_factory = aiosqlite.Row
cursor = await conn.execute( cursor = await conn.execute(
""" """
UPDATE articles SET UPDATE articles SET
@ -121,6 +125,7 @@ class ArticleRepository:
params = params + (limit,) params = params + (limit,)
async with await self.db_service.get_connection() as conn: async with await self.db_service.get_connection() as conn:
conn.row_factory = aiosqlite.Row
cursor = await conn.execute(query, params) cursor = await conn.execute(query, params)
rows = await cursor.fetchall() rows = await cursor.fetchall()
@ -131,6 +136,7 @@ class ArticleRepository:
async def count_by_status(self, status: ArticleStatus) -> int: async def count_by_status(self, status: ArticleStatus) -> int:
async with await self.db_service.get_connection() as conn: async with await self.db_service.get_connection() as conn:
conn.row_factory = aiosqlite.Row
cursor = await conn.execute( cursor = await conn.execute(
"SELECT COUNT(*) FROM articles WHERE status = ?", "SELECT COUNT(*) FROM articles WHERE status = ?",
(status.value,), (status.value,),
@ -148,6 +154,7 @@ class ArticleRepository:
params = (limit, offset) params = (limit, offset)
async with await self.db_service.get_connection() as conn: async with await self.db_service.get_connection() as conn:
conn.row_factory = aiosqlite.Row
cursor = await conn.execute(query, params) cursor = await conn.execute(query, params)
rows = await cursor.fetchall() rows = await cursor.fetchall()
@ -155,6 +162,7 @@ class ArticleRepository:
async def delete_article(self, article_id: int) -> bool: async def delete_article(self, article_id: int) -> bool:
async with await self.db_service.get_connection() as conn: async with await self.db_service.get_connection() as conn:
conn.row_factory = aiosqlite.Row
cursor = await conn.execute( cursor = await conn.execute(
"DELETE FROM articles WHERE id = ?", "DELETE FROM articles WHERE id = ?",
(article_id,), (article_id,),