python - 如何让 SQL Alchemy and_ 动态化
问题描述
我将用户输入作为逗号分隔值。
name, grade, admission_number
用户将至少提供其中之一。我需要构建and_()
它以使其相应地过滤。
session.query(Student).filter(and_( Student.name == name, Student.grade == grade ))
如果用户只提供学生的姓名,那么上述语句将查找成绩为空字符串的学生。
我需要能够and_
根据用户提供的任何值来构建它。
解决方案
推荐阅读
- sequelize.js - Sequelizejs:错误:重复键值违反唯一约束“message_pkey”
- c# - DateTime 现在将 Datetime 字符串转换为指定格式
- bitbucket - Bitbucket 存储库的大小限制是否包括其中的分支和标签?
- node.js - 正则表达式在聚合查询mongodb中搜索整数?
- swift - 使用 Firebase 存储数据库填充 TableView
- oracle - 选择查询返回结果集,但在创建具有相同查询的视图时得到 ORA-00957
- dart - 在颤振中从 tab1 切换到 tab3 会出现错误 - 最小颤振 App
- scala - 错误:`<<=` 运算符已删除。使用 `key := { x.value }` 或 `key ~= (old => { newValue })`
- javascript - 如何在javascript中找到对象的indexof
- c# - 是否可以在 Entity Framework Core 2.1 版上自动映射数据库视图?