update db_model
This commit is contained in:
parent
d4e6c52286
commit
1ece3484a3
|
@ -1,4 +1,5 @@
|
|||
from sqlalchemy import Column, DateTime, Boolean, func
|
||||
from sqlalchemy.orm import Query
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from datetime import datetime
|
||||
|
||||
|
@ -23,6 +24,13 @@ class BaseCrud(BaseModel):
|
|||
return session.query(cls).filter().filter_by(**kwargs).first()
|
||||
return session.query(cls).filter().filter_by(**kwargs).offset(start).limit(count).all()
|
||||
|
||||
@classmethod
|
||||
def filtered_query(cls, session, filter_args=None, filter_kwargs=None) -> Query:
|
||||
if filter_args:
|
||||
return session.query(cls).filter(*filter_args).filter_by(**filter_kwargs)
|
||||
else:
|
||||
return session.query(cls).filter().filter_by(**filter_kwargs)
|
||||
|
||||
# 增
|
||||
@classmethod
|
||||
def create(cls, session, **kwargs):
|
||||
|
@ -45,10 +53,10 @@ class BaseCrud(BaseModel):
|
|||
return self
|
||||
|
||||
|
||||
# 提供软删除,及创建时间,更新时间信息的crud model
|
||||
|
||||
|
||||
class InfoCrud(BaseModel):
|
||||
"""
|
||||
提供软删除,及创建时间,更新时间信息的crud model
|
||||
"""
|
||||
|
||||
__abstract__ = True
|
||||
|
||||
|
@ -80,6 +88,13 @@ class InfoCrud(BaseModel):
|
|||
return session.query(cls).filter().filter_by(**kwargs).first()
|
||||
return session.query(cls).filter().filter_by(**kwargs).offset(start).limit(count).all()
|
||||
|
||||
@classmethod
|
||||
def filtered_query(cls, session, filter_args=None, filter_kwargs=None) -> Query:
|
||||
if filter_args:
|
||||
return session.query(cls).filter(*filter_args).filter_by(**filter_kwargs)
|
||||
else:
|
||||
return session.query(cls).filter().filter_by(**filter_kwargs)
|
||||
|
||||
# 增
|
||||
@classmethod
|
||||
def create(cls, session, **kwargs):
|
||||
|
|
Loading…
Reference in New Issue