- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何在flutter中用sembast
库实现insert if no records with the id else update?我试过下面的。
Future updateOrInsert(User user) async {
final result = await update(user);
if(result == 0){
insert(user);
}
}
Future update(User user) async {
final finder = Finder(filter: Filter.byKey(user.id));
final result = await _userStore.update(await _db, user.toMap(), finder: finder);
return result;
}
Future insert(User user) async {
await _userStore.add(await _db, user.toMap());
}
它工作正常。这是正确的解决方案还是有任何其他可用的直接 sembast API?
最佳答案
您应该使用 Record.put
添加或更新具有给定 ID 的记录。
Future updateOrInsert(User user) async {
await _userStore.record(user.id).put(_db, user.toMap());
}
关于Flutter Sembast 插入或更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59578986/
我在 Flutter 应用程序中使用 Sembast。我必须刷新商店中的所有数据,并且需要一种方法来删除商店中的所有文档。我查看了 API,我能看到的唯一方法是获取所有 key 并在查找器中使用它们来
如何在flutter中用sembast库实现insert if no records with the id else update?我试过下面的。 Future updateOrInsert(Use
我即将在 Flutter 中使用数据库“Sembast”。具有 string 和 int 等数据类型的简单对象可以正常工作。但是,使用列表时会出现问题。 我已经创建了一个示例并以以下教程为导向:htt
我尝试将 flutter 与 sembast nosql 数据库结合起来。我创建了一种方法来获取所有数据库文档并编辑给定数据。 我的方法如下所示: Future> getAll() async {
我有一个存储 map 对象的Sembast商店。如果要删除 map 中的键,是否必须更新整个 map 对象,或者是否有办法在不更新整个 map 的情况下删除 key ?这些文档仅显示如何删除记录,而没
我是一名优秀的程序员,十分优秀!