@@ -173,15 +173,11 @@ - (void)update:(id<SJDBMapUseProtocol>)model property:(NSArray<NSString *> *)fie
173173 [self addOperationWithBlock: ^{
174174 [self queryDataWithClass: [model class ] primaryValue: [[self sjGetPrimaryOrAutoPrimaryValue: model] integerValue ] completeCallBlock: ^(id <SJDBMapUseProtocol> _Nullable m) {
175175 if ( nil == m ) {
176- dispatch_async (dispatch_get_main_queue (), ^{
177- if ( block ) block (NO );
178- });
176+ if ( block ) block (NO );
179177 return ;
180178 }
181179 BOOL result = [self sjUpdate: model property: fields];
182- dispatch_async (dispatch_get_main_queue (), ^{
183- if ( block ) block (result);
184- });
180+ if ( block ) block (result);
185181 }];
186182 }];
187183}
@@ -197,17 +193,32 @@ - (void)update:(id<SJDBMapUseProtocol>)model insertedOrUpdatedValues:(NSDictiona
197193 [self addOperationWithBlock: ^{
198194 [self queryDataWithClass: [model class ] primaryValue: [[self sjGetPrimaryOrAutoPrimaryValue: model] integerValue ] completeCallBlock: ^(id <SJDBMapUseProtocol> _Nullable m) {
199195 if ( nil == m ) {
200- dispatch_async (dispatch_get_main_queue (), ^{
201- if ( block ) block (NO );
202- });
196+ if ( block ) block (NO );
203197 return ;
204198 }
205199
206200 BOOL result = [self sjUpdate: model insertedOrUpdatedValues: insertedOrUpdatedValues];
207- dispatch_async (dispatch_get_main_queue (), ^{
208- if ( block ) block (result);
209- });
210-
201+ if ( block ) block (result);
202+ }];
203+ }];
204+ }
205+
206+ /* !
207+ * 此接口针对数组字段使用.
208+ * 如果数据库没有这个模型, 将不会保存
209+ *
210+ * deletedValues : key 更新的这个模型对应的属性(字段为数组). value 数组中删除掉的模型.
211+ */
212+ - (void )update : (id <SJDBMapUseProtocol>)model deletedValues : (NSDictionary <NSString *, id> *__nullable)deletedValues callBlock : (void (^)(BOOL ))block {
213+ if ( 0 == deletedValues.allKeys ) { if ( block ) block (NO ); return ;}
214+ [self addOperationWithBlock: ^{
215+ [self queryDataWithClass: [model class ] primaryValue: [[self sjGetPrimaryOrAutoPrimaryValue: model] integerValue ] completeCallBlock: ^(id <SJDBMapUseProtocol> _Nullable m) {
216+ if ( nil == m ) {
217+ if ( block ) block (NO );
218+ return ;
219+ }
220+ BOOL result = [self sjInsertOrUpdateDataWithModel: model uM: [self sjGetUnderstandingWithClass: [model class ]]];
221+ if ( block ) block (result);
211222 }];
212223 }];
213224}
0 commit comments