Files
PVHBackend/db/handlers/catigory_handler.py
T
2026-03-17 12:08:19 +03:00

24 lines
688 B
Python

import sqlite3
from module.category import Category
def GetAllCategories(db_name: str = 'pipe_store.db', parent_id: int = 1) -> list[Category]:
conn = sqlite3.connect(db_name)
conn.row_factory = sqlite3.Row
cursor = conn.cursor()
categories = []
cursor.execute("SELECT id, name, description, image_path FROM categories WHERE parent_id = ?", [parent_id])
for row in cursor.fetchall():
category = Category(
id = row["id"],
name = row["name"],
description= row["description"],
image_path= row["image_path"],
)
categories.append(category.model_dump())
conn.close()
return categories