From 0eb29bdc10ad3d798f12bd7be7ede6dfd4a14ab4 Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Mon, 22 May 2023 08:29:03 -0500 Subject: [PATCH] add where --- learn_sql_model/models/fast_model.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/learn_sql_model/models/fast_model.py b/learn_sql_model/models/fast_model.py index 0c40bd5..380f8fc 100644 --- a/learn_sql_model/models/fast_model.py +++ b/learn_sql_model/models/fast_model.py @@ -26,24 +26,25 @@ class FastModel(SQLModel): self.pre_post() - instance = self.__class__(**self.dict()) - - with config.database.session() as session: + with config.database.session as session: session.add(self) session.commit() - return instance - def get(self, id: int = None, config: "Config" = None) -> Optional["FastModel"]: + def get( + self, id: int = None, config: "Config" = None, where=None + ) -> Optional["FastModel"]: if config is None: config = get_config() self.pre_get() - with config.database.session() as session: + with config.database.session as session: if id is None: print("get all") statement = select(self.__class__) + if where is not None: + statement = statement.where(where).options() results = session.exec(statement).all() else: print("get by id")