recopytex/backend/repository/tribe_sqlite_repository.py

43 lines
987 B
Python

from backend.model.tribe import Tribe
from backend.repository.abstract_repository import AbstractRepository
class TribeSQLiteRepository(AbstractRepository):
def __init__(self, conn) -> None:
self.conn = conn
def add(self, tribe: Tribe) -> None:
pass
def update(self, name: str, tribe: Tribe) -> None:
pass
def get(self, name: str) -> Tribe:
cursor = self.conn.cursor()
cursor.execute(
"""
SELECT * FROM tribes WHERE name=?
""",
(name,),
)
row = cursor.fetchone()
if row:
return Tribe(*row)
raise ValueError(f"The tribe {name} does not exists")
def list(self) -> list[Tribe]:
cursor = self.conn.cursor()
cursor.execute(
"""
SELECT * FROM tribes
"""
)
rows = cursor.fetchall()
return [Tribe(*r) for r in rows]
def delete(self, tribe: Tribe) -> None:
pass