新增支持获取单个数据时不需要筛选条件
This commit is contained in:
parent
df767ed3cf
commit
cbfd2e4074
@ -61,14 +61,15 @@ class DalBase:
|
|||||||
if key != "order" and key != "return_none" and value and getattr(self.model, key, None):
|
if key != "order" and key != "return_none" and value and getattr(self.model, key, None):
|
||||||
kwargs_exist = True
|
kwargs_exist = True
|
||||||
break
|
break
|
||||||
data = None
|
|
||||||
if data_id or kwargs_exist or keys_exist:
|
if data_id or kwargs_exist or keys_exist:
|
||||||
sql = select(self.model).where(self.model.id == data_id) if data_id else select(self.model)
|
sql = select(self.model).where(self.model.id == data_id) if data_id else select(self.model)
|
||||||
sql = self.add_filter_condition(sql, keys, options, **kwargs)
|
sql = self.add_filter_condition(sql, keys, options, **kwargs)
|
||||||
if order and order == "desc":
|
else:
|
||||||
sql = sql.order_by(self.model.create_datetime.desc())
|
sql = select(self.model)
|
||||||
queryset = await self.db.execute(sql)
|
if order and order == "desc":
|
||||||
data = queryset.scalars().first()
|
sql = sql.order_by(self.model.create_datetime.desc())
|
||||||
|
queryset = await self.db.execute(sql)
|
||||||
|
data = queryset.scalars().first()
|
||||||
if not data and return_none:
|
if not data and return_none:
|
||||||
return None
|
return None
|
||||||
if data and schema:
|
if data and schema:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user