我有以下颤动沼泽查询
(select(recipeGarnishes)..where((tbl) => tbl.postGarnish.equals(true))).get();
我该如何添加distinct
查询条件?
更新:
我想写的查询是:
select DISTINCT garnishName from RecipeGarnishes where postGarnish = 'true'
garnishName
and postGarnish
是我的列RecipeGarnishes
table
更新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();
但它给了我以下错误
Moor:发送 SELECT DISTINCTrecipe_garnishes.garnish_name AS“recipe_garnishes.garnish_name”FROMrecipe_garnishes WHERErecipe_garnishes.post_garnish = ?;带参数 [1]
[错误:flutter/lib/ui/ui_dart_state.cc(166)] 未处理的异常:NoSuchMethodError:在 null 上调用 getter 'garnishName'。
查询本身是正确的,但您无法像这样读取结果: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();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)