diff --git a/SJDBMap.podspec b/SJDBMap.podspec index 9a7dd0c..f5f9ed4 100644 --- a/SJDBMap.podspec +++ b/SJDBMap.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "SJDBMap" -s.version = "1.0.21" +s.version = "1.0.22" s.summary = "Automatically create tables based on the model." s.description = "https://github.com/changsanjiang/SJDBMap/blob/master/README.md" s.homepage = "https://github.com/changsanjiang/SJDBMap" diff --git a/SJDBMap/Category/SJDatabaseMap+Server.m b/SJDBMap/Category/SJDatabaseMap+Server.m index ed5dfee..09290e6 100644 --- a/SJDBMap/Category/SJDatabaseMap+Server.m +++ b/SJDBMap/Category/SJDatabaseMap+Server.m @@ -454,6 +454,8 @@ - (BOOL)sjUpdate:(id)model property:(NSArray *)f [self _sjBeginTransaction]; + [self sjCreateOrAlterTabWithClass:[model class]]; + // 查看是否有特殊字段 NSDictionary *> *putInOrderResult = [self _sjPutInOrderModel:model fields:fields]; @@ -497,10 +499,12 @@ - (BOOL)_sjUpdate:(id)model uniqueFields:(NSArray)model insertedOrUpdatedValues:(NSDictio id uniqueValue = [(id)model valueForKey:obj]; // is Arr if ( [uniqueValue isKindOfClass:[NSArray class]] ) { + [self sjCreateOrAlterTabWithClass:[[uniqueValue firstObject] class]]; result = [self sjInsertOrUpdateDataWithModels:uniqueValue enableTransaction:NO]; if ( !result ) { *stop = YES;} return; } // is cor SJDBMapUnderstandingModel *uM = [self sjGetUnderstandingWithClass:[uniqueValue class]]; + [self sjCreateOrAlterTabWithClass:uniqueValue]; result = [self sjInsertOrUpdateDataWithModel:uniqueValue uM:uM]; if ( !result ) { *stop = YES;} }]; diff --git a/SJDBMap/SJDatabaseMap.h b/SJDBMap/SJDatabaseMap.h index d07c950..fa3e228 100755 --- a/SJDBMap/SJDatabaseMap.h +++ b/SJDBMap/SJDatabaseMap.h @@ -56,6 +56,14 @@ NS_ASSUME_NONNULL_BEGIN @interface SJDatabaseMap (InsertOrUpdate) + +// MARK: --------------------------------------------------------- +/*! + * 数据库依据模型来存储. 所以在存储之前, 请将模型更新到最新状态, 再进行存储. + */ +// MARK: --------------------------------------------------------- + + /*! * 插入数据或更新数据 * 如果没有表, 会自动创建表 @@ -84,15 +92,14 @@ NS_ASSUME_NONNULL_BEGIN * * insertedOrUpdatedValues : key 更新的这个模型对应的属性. value 属性 更新/新增 的模型, 可以是数组, 也可以是单个模型 */ -- (void)update:(id)model insertedOrUpdatedValues:(NSDictionary * __nullable)insertedOrUpdatedValues callBlock:(void (^)(BOOL))block; +- (void)update:(id)model insertedOrUpdatedValues:(NSDictionary * __nullable)insertedOrUpdatedValues callBlock:(void (^)(BOOL result))block; /*! * 此接口针对数组字段使用. * 如果数据库没有这个模型, 将不会保存 * - * deletedValues : key 更新的这个模型对应的属性(字段为数组). value 数组中删除掉的模型. */ -- (void)updateTheDeletedValuesInTheModel:(id)model callBlock:(void (^)(BOOL))block; +- (void)updateTheDeletedValuesInTheModel:(id)model callBlock:(void (^)(BOOL result))block; @end diff --git a/SJDBMap/SJDatabaseMap.m b/SJDBMap/SJDatabaseMap.m index 13213c4..630e6fc 100755 --- a/SJDBMap/SJDatabaseMap.m +++ b/SJDBMap/SJDatabaseMap.m @@ -208,7 +208,6 @@ - (void)update:(id)model insertedOrUpdatedValues:(NSDictiona * 此接口针对数组字段使用. * 如果数据库没有这个模型, 将不会保存 * - * deletedValues : key 更新的这个模型对应的属性(字段为数组). value 数组中删除掉的模型. */ - (void)updateTheDeletedValuesInTheModel:(id)model callBlock:(void (^)(BOOL))block { [self addOperationWithBlock:^{