Spaces:
Sleeping
Sleeping
from db.models import Category, Metadata | |
from db.query.base_query import BaseQuery | |
from sqlalchemy import select, delete, update | |
class CategoryQuery(BaseQuery): | |
def __init__(self, user): | |
super().__init__(user) | |
def add_category(self, db, name): | |
new_category = Category(name=name, user_id=self.user["id"]) | |
return self.add(db, new_category) | |
def update_category(self, db, category_id, name): | |
update_data = {"name": name} | |
self.update(db, Category, category_id, update_data) | |
def delete_category(self, db, category_id): | |
self.delete(db, Category, category_id) | |
def get_category(self, db, category_id): | |
columns = [Category.category] | |
model = Category | |
return self.get_columns(db,model=model, columns=columns, id=category_id) | |
def get_current_category(self, db, metadata_id): | |
columns = [Category.category] | |
join_models = [Metadata] | |
where_conditions = [Metadata.id == metadata_id] | |
result = self.get_with_joins( | |
db, | |
join_models=join_models, | |
filter_conditions=where_conditions, | |
columns=columns, | |
multiple=False # Assuming you want a single result | |
) | |
return result | |
def get_all_categories(self, db): | |
return self.get(db, Category, multiple=True) | |