sqlite - 如何编写在 Flutter/moor 中返回 Future 的 cotomselect 查询
问题描述
我正在通过颤振/摩尔开发应用程序。但我不知道如何编写返回 Future<List> 类对象的自定义查询。
我可以编写返回 Stream 类对象的查询。但这还不够。现在有没有人如何将其更改为返回 Future 类的方法。
我写的查询如下
db.dart
Stream<List<QuestionHeader>> selectQuestionHeaderByKey(int businessYear,int period, int questionNo) {
return
customSelect(
'SELECT *'
+'From question_Headers '
+'WHERE business_Year = ? '
+'AND period = ? '
+'AND question_No = ?;',
variables: [Variable.withInt(businessYear),Variable.withInt(period),Variable.withInt(questionNo)],
readsFrom: {questionHeaders},
).watch().map((rows) {
return rows
.map((row) => QuestionHeader(
businessYear:row.readInt('businessYear')
,period:row.readInt('period')
,questionNo:row.readInt('questionNo')
,subjectId:row.readInt('subjectId')
,compulsoryType:row.readInt('compulsoryType')
,answerType:row.readInt('answerType')
,questionText:row.readString('questionText')
,numberAnswer:row.readInt('numberAnswer')
,correctType1:row.readInt('correctType1')
,correctType2:row.readInt('correctType2')
,correctType3:row.readInt('correctType3')
,favorite:row.readBool('favorite')
)).toList();
});
}
这可行,但我需要 Future<List> 类返回。
解决方案
推荐阅读
- r - 组为空时 data.table 中的子集
- sql - 在 CASE 表达式中返回一个值而不是文本
- php - 如何使用从 mysql 数据库检索到的值填充下拉列表?
- python - 调试长时间运行的 python 脚本崩溃?
- oauth-2.0 - 刷新令牌 OAuth2 实现
- c# - 如何在不使用 FormsCollection 的情况下拥有两个不同的 ViewModel 并将数据从两者提交到控制器?
- javascript - 承诺没有得到解决
- azure-devops - 带有 SSH 服务连接的 Azure Devops 多配置不起作用
- ruby-on-rails - 在 Linux 上安装 ruby-oci8 时无法编译 OCI 错误
- powershell - 在 powershell 中跟踪 Maven 命令状态