add where

This commit is contained in:
Waylon Walker 2023-05-22 08:29:03 -05:00
parent 99908c6a5a
commit 0eb29bdc10
No known key found for this signature in database
GPG key ID: 66E2BF2B4190EFE4

View file

@ -26,24 +26,25 @@ class FastModel(SQLModel):
self.pre_post() self.pre_post()
instance = self.__class__(**self.dict()) with config.database.session as session:
with config.database.session() as session:
session.add(self) session.add(self)
session.commit() 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: if config is None:
config = get_config() config = get_config()
self.pre_get() self.pre_get()
with config.database.session() as session: with config.database.session as session:
if id is None: if id is None:
print("get all") print("get all")
statement = select(self.__class__) statement = select(self.__class__)
if where is not None:
statement = statement.where(where).options()
results = session.exec(statement).all() results = session.exec(statement).all()
else: else:
print("get by id") print("get by id")