#6 Added Database functionality for user to click and load a single item

This commit is contained in:
2024-01-23 17:53:00 +00:00
parent 1f518ff56d
commit 95768f8a8c
4 changed files with 35 additions and 1 deletions

View File

@ -55,6 +55,26 @@ class ProductController(DatabaseController):
return products
def read_id(self, id: int) -> Product | None:
params = [
id
]
cursor = self._conn.execute(
"SELECT * FROM Products WHERE id == ?",
params
)
row = cursor.fetchone()
if row is None:
return None
# Create an object with the row
params = dict(zip(self.FIELDS, row))
obj = self.new_instance(Product, params)
return obj
def read_all(self, category: str = "",
search_term: str = "") -> list[Product] | None:
params = [