forked from iti-framework/iTi-Flask
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
591 B
Python
30 lines
591 B
Python
from sqlalchemy.ext.declarative import DeclarativeBase
|
|
|
|
|
|
def is_sqlalchemy_model(obj):
|
|
"""
|
|
判断对象是否为 SQLAlchemy 模型
|
|
"""
|
|
if isinstance(obj, DeclarativeBase):
|
|
return True
|
|
|
|
if hasattr(obj, "_sa_instance_state"):
|
|
return True
|
|
|
|
if hasattr(obj, "__mapper__"):
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
def is_orm_result(data):
|
|
"""
|
|
判断数据是否为 ORM 查询结果
|
|
"""
|
|
if isinstance(data, list):
|
|
if not data:
|
|
return False
|
|
return is_sqlalchemy_model(data[0])
|
|
|
|
return is_sqlalchemy_model(data)
|