Drk*_*Str 2 flutter flutter-moor
我有以下颤动沼泽查询
(select(recipeGarnishes)..where((tbl) => tbl.postGarnish.equals(true))).get();
Run Code Online (Sandbox Code Playgroud)
我如何将distinct条件添加到查询中?
更新:我想写的查询是:
select DISTINCT garnishName from RecipeGarnishes where postGarnish = 'true'
Run Code Online (Sandbox Code Playgroud)
garnishName而postGarnish在我列RecipeGarnishes的表
更新 2:
根据答案,我尝试了这个。
final query = selectOnly(recipeGarnishes, distinct: true)
..addColumns([recipeGarnishes.garnishName])
..where(recipeGarnishes.postGarnish.equals(postGarnish));
List<TypedResult> result = await query.get();
return result.map((row) => row.readTable(recipeGarnishes)).toList();
Run Code Online (Sandbox Code Playgroud)
但它给了我以下错误
摩尔:发送 SELECT DISTINCT recipe_garnishes.garnish_name AS "recipe_garnishes.garnish_name" FROM recipe_garnishes WHERE recipe_garnishes.post_garnish = ?; 带参数 [1]
[错误:flutter/lib/ui/ui_dart_state.cc(166)] 未处理的异常:NoSuchMethodError:getter 'garnishName' 在 null 上被调用。
查询本身是正确的,但您无法读取这样的结果:row.readTable将返回包含所有列的完整行。但是,您只选择了一个列 ( garnishName),因此 moor 无法加载该行并返回null。
您可以使用
final query = selectOnly(recipeGarnishes, distinct: true)
..addColumns([recipeGarnishes.garnishName])
..where(recipeGarnishes.postGarnish.equals(postGarnish));
return query.map((row) => row.read(recipeGarnishes.garnishName)).get();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
801 次 |
| 最近记录: |