我正在尝试使用flutter的moor包为我的数据库实现一个多值过滤器。
moor已经有了where方法,该方法接受表达式并将其转换为sql语句。像这样:
(select(exercisesTable)..where((e) => (e.name.equals(name)))).get(); 但我需要过滤数据,因为有多个值。在我搜索了文档之后,我找到了两个可能的解决方案:
CutomExpressionClass 链接:
表达式= CustomExpression(“水在4.0到5.0之间,蛋白质在4.0到15.0之间,描述像国际象棋%”);
但是我得到了一个错误:*
SqliteException:近";":语法错误,SQL逻辑错误*
Custom select statements 链接:
我没有尝试过这一点,因为我认为问题在于sql本身,而不是moor包。发布于 2020-08-27 07:13:17
来自SingleTableQueryMixin::where方法(链接)的注释:
...
/// If a where condition has already been set before, the resulting filter
/// will be the conjunction of both calls.
...根据这一点,您可以使用这样的东西:
Future<List<TableData>> getTableList({int position, int type}) {
final _select = select(table);
if (position != null) {
_select..where((tbl) => tbl.position.equals(position));
}
if (type != null) {
_select..where((tbl) => tbl.type.equals(type));
}
return _select.get();
}发布于 2021-12-03 23:41:24
您可以使用布尔代数特性具有多个where条件。
// find all animals that aren't mammals and have 4 legs
select(animals)..where((a) => a.isMammal.not() & a.amountOfLegs.equals(4));
// find all animals that are mammals or have 2 legs
select(animals)..where((a) => a.isMammal | a.amountOfLegs.equals(2));https://stackoverflow.com/questions/60971654
复制相似问题