from model_data_api.model.base_model import BaseManager
from model_data_api.model.tab_model import TabModelsData


class ModelsDataManager(BaseManager):
    def find_all(self):
        return self.get_json(self.session.query(TabModelsData).all())

    def find_single(self, name):
        return self.get_json(self.session.query(TabModelsData).filter_by(name = name))

    def find_condition(self, **kwargs):
        return self.session.query(TabModelsData).filter(**kwargs)

    def create_obj(self,name, content,create_name ,el_expression):
        p = TabModelsData(name=name,content=content,create_name=create_name,el_expression=el_expression)
        self.session.add(p)
        self.session.commit()