范例:只使用数据库扩展
查看以下链接,以阅览该基础范例。
该范例提供了以下功能:
- 一个包含两个表(
new_model
和numerical_model
)的超简单数据库。 new_model
和numerical_model
之间通过一对多关系链接。- 每个
numerical_model
数据项包含一个浮点数值。 - 范例将会透过向
numerical_model
施加不同的条件,逐个检索子项符合给定条件的new_model
数据项。
数据库的实体关系图(entity-relationship diagram, ERD)如下:
检索的结果应当如下:
16:41:05,028 flask-sqlalchemy-compat.example INFO Start to add testing data.
16:41:05,036 flask-sqlalchemy-compat.example INFO Start to query data.
16:41:05,036 flask-sqlalchemy-compat.example INFO Query by name.
16:41:05,041 flask-sqlalchemy-compat.example INFO Queried: NewModel(id=3, name=mixed, n_vals=3)
16:41:05,041 flask-sqlalchemy-compat.example INFO Query all models having positive values.
16:41:05,043 flask-sqlalchemy-compat.example INFO Queried: [NewModel(id=1, name=only-pos, n_vals=3), NewModel(id=3, name=mixed, n_vals=3)]
16:41:05,043 flask-sqlalchemy-compat.example INFO Query all models having negative values.
16:41:05,045 flask-sqlalchemy-compat.example INFO Queried: [NewModel(id=2, name=only-neg, n_vals=3), NewModel(id=3, name=mixed, n_vals=3)]
16:41:05,045 flask-sqlalchemy-compat.example INFO Query all models having both positive and negative values.
16:41:05,047 flask-sqlalchemy-compat.example INFO Queried: [NewModel(id=3, name=mixed, n_vals=3)]