Spaces:
Sleeping
Sleeping
from db.models import Category, Metadata | |
from db.query.base_query import BaseQuery | |
class CategoryQuery(BaseQuery): | |
def __init__(self, user): | |
super().__init__(user) | |
def add_category(self, db, category_name): | |
new_category = Category(category=category_name) | |
return self.add(db, new_category) | |
def update_category(self, db, category_id, category_name): | |
update_data = {"category": category_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 | |
results = self.get_columns(db,model=model, columns=columns, id=category_id) | |
return results | |
def get_existing_category(self, db, category_name): | |
columns = [Category.category] | |
model = Category | |
filter_condition = [Category.category == category_name] | |
results = self.get_columns(db, columns=columns, model=model, filter_conditions=filter_condition) | |
return results | |
def get_category_by_id(self, db, category_id): | |
model = Category | |
filter_conditions = [Category.id == category_id] | |
results = self.get(db, model=model, filter_conditions=filter_conditions) | |
return results | |
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): | |
results = self.get(db, Category, multiple=True) | |
categories = [category[0] for category in results] | |
return categories |