python - SQLAlchemy:用存储过程或更复杂的 sql 语句填充对象
问题描述
我有一个名为 Feature 的 sql 炼金术类。
class Feature(DBConnect.Base):
__tablename__ = 'feature'
id = Column(Integer, primary_key=True)
name = Column(String(500), nullable=False, default='')
在其他代码中,我可以通过执行以下操作获得功能:
feature = db.session.query(Feature).get(10)
我最终得到了一个特征对象。是否可以执行存储过程或更复杂的查询,如下所示:
select * from feature f
join aligned_data_column a on a.id=f.aligned_Data_column_id and
a.aligned_data_id=76
where a.aligned_data_id=70
union
select * from feature f
join aligned_data_column a on a.aligned_data_id=76
where json_contains(json_extract(f.column_mappings, '$.*'),CAST(a.id as JSON))
我希望能够将该查询输入到存储过程或代码中的某个位置。我正在使用 MySQL 和 python 3.x
解决方案
推荐阅读
- css - Bootstrap:主体上的模态和变换比例
- java - YouTubePlayerView 画中画安卓
- python - 不可能训练神经网络计算异或
- r - data.table 分配多个列,生成为新的 data.table(或列表)而不重复名称
- unity3d - Unity Admob 插页式广告不显示
- c# - .Net (Xamarin) 共享库适用于 Android 但不适用于 iOS
- c# - XmlTextReader 是否容易受到 XXE 攻击?
- javascript - 如何使用 ReactJS 创建固定侧边栏?侧边栏应在较小的屏幕中折叠
- java - Javascript - Java ECDH
- python - tf.keras - 导入具有批标准化层的模型