ios - 放大 DataStore 同步表达式未重新评估
问题描述
我在我的 iOS 应用程序中使用 Amplify DataStore,并且我正在使用以下自定义同步表达式有选择地同步我的数据子集:
func setSyncExpression(idVariable: String) -> [DataStoreSyncExpression] {
let postSyncExpression = DataStoreSyncExpression.syncExpression(Post.schema) {
Post.keys.year.ge(2020).and(Post.product.eq("ProductA"))
}
let customerSyncExpression = DataStoreSyncExpression.syncExpression(Customer.schema) {
Customer.keys.customerNumber.eq(idVariable)
}
let customSyncEpression = [postSyncExpression, customerSyncExpression]
return customSyncEpression
}
初始化 Amplify 时使用此表达式:
public var customerId: String = "001A"
func configureAmplify() {
let customSyncExpressions = setSyncExpression(idVariable: customerId)
let apiPlugin = AWSAPIPlugin()
let dataStorePlugin = AWSDataStorePlugin(modelRegistration: AmplifyModels(),
configuration: .custom(syncExpressions:
customSyncExpressions))
do {
try Amplify.add(plugin: dataStorePlugin)
try Amplify.add(plugin: apiPlugin)
try Amplify.configure()
} catch {
print("Could not initialize Amplify: \(error)")
}
}
根据Amplify Docs:每当 DataStore 启动时,都会评估同步表达式。为了重新评估您的表达式,您可以执行 Amplify.DataStore.stop()
后跟 Amplify.DataStore.start()
.
但是,如果我将customerId
变量设置为"002A"
并重新启动 DataStore,我的数据库中与这个新的 customerNumber 匹配的所有项目都不会同步。
我能够重新同步的唯一方法customerId = "002A"
是运行Amplify.DataStore.clear()
. 但是,这会清除所有其他模型的所有内容,并强制这些模型也重新同步,这需要很长时间。
如何重新运行选择性同步以从客户模型中提取其他项目?(我知道匹配第一次同步的现有本地数据"001A"
也将仍然存在而不运行.clear
)
或者,有什么方法可以选择性地清除单个模型而不影响其他模型中的本地数据?
解决方案
推荐阅读
- android - 如何在高度约束文本小部件中获取字符串的最后一个合适的单词?
- vue.js - 在 Vue 模板中存储对象
- android - ADB 无法在 Android 11 上启动 IMAGE_CAPTURE 意图活动
- datetime - x 轴上的日期 - OCTAVE
- javascript - FullCalendar 5 - eventDrop 第一次无法编辑事件道具?
- python - Django 石墨烯,按对象过滤
- powerbi - DAX 创建带有附加字段的日历表
- flutter - SlidingUpPanel 中的 ListView 滚动
- python - 使用参数作为变量的一部分
- javascript - 适配一个 jQuery 函数来发送文件