#6 Added Database functionality for user to click and load a single item
This commit is contained in:
@ -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 = [
|
||||
|
Reference in New Issue
Block a user