Skip to content

Commit 66b4db0

Browse files
committed
Update [ Update methods Added Alert Fields ]
1 parent 8467168 commit 66b4db0

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

SJDBMap.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Pod::Spec.new do |s|
33
s.name = "SJDBMap"
4-
s.version = "1.0.21"
4+
s.version = "1.0.22"
55
s.summary = "Automatically create tables based on the model."
66
s.description = "https://github.com/changsanjiang/SJDBMap/blob/master/README.md"
77
s.homepage = "https://github.com/changsanjiang/SJDBMap"

SJDBMap/Category/SJDatabaseMap+Server.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ - (BOOL)sjUpdate:(id<SJDBMapUseProtocol>)model property:(NSArray<NSString *> *)f
454454

455455
[self _sjBeginTransaction];
456456

457+
[self sjCreateOrAlterTabWithClass:[model class]];
458+
457459
// 查看是否有特殊字段
458460
NSDictionary<NSString *, NSArray<NSString *> *> *putInOrderResult = [self _sjPutInOrderModel:model fields:fields];
459461

@@ -497,10 +499,12 @@ - (BOOL)_sjUpdate:(id<SJDBMapUseProtocol>)model uniqueFields:(NSArray<NSString *
497499
// is Arr
498500
if ( [uniqueValue isKindOfClass:[NSArray class]] ) {
499501
// insert arr values
502+
[self sjCreateOrAlterTabWithClass:[[uniqueValue firstObject] class]];
500503
result = [self sjInsertOrUpdateDataWithModels:uniqueValue enableTransaction:NO];
501504
return;
502505
}
503506
// is cor
507+
[self sjCreateOrAlterTabWithClass:[uniqueValue class]];
504508
if ( result ) result = [self sjInsertOrUpdateDataWithModel:uniqueValue uM:[self sjGetUnderstandingWithClass:[uniqueValue class]]];
505509
}];
506510

@@ -575,12 +579,14 @@ - (BOOL)sjUpdate:(id<SJDBMapUseProtocol>)model insertedOrUpdatedValues:(NSDictio
575579
id uniqueValue = [(id)model valueForKey:obj];
576580
// is Arr
577581
if ( [uniqueValue isKindOfClass:[NSArray class]] ) {
582+
[self sjCreateOrAlterTabWithClass:[[uniqueValue firstObject] class]];
578583
result = [self sjInsertOrUpdateDataWithModels:uniqueValue enableTransaction:NO];
579584
if ( !result ) { *stop = YES;}
580585
return;
581586
}
582587
// is cor
583588
SJDBMapUnderstandingModel *uM = [self sjGetUnderstandingWithClass:[uniqueValue class]];
589+
[self sjCreateOrAlterTabWithClass:uniqueValue];
584590
result = [self sjInsertOrUpdateDataWithModel:uniqueValue uM:uM];
585591
if ( !result ) { *stop = YES;}
586592
}];

SJDBMap/SJDatabaseMap.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ NS_ASSUME_NONNULL_BEGIN
5656

5757
@interface SJDatabaseMap (InsertOrUpdate)
5858

59+
60+
// MARK: ---------------------------------------------------------
61+
/*!
62+
* 数据库依据模型来存储. 所以在存储之前, 请将模型更新到最新状态, 再进行存储.
63+
*/
64+
// MARK: ---------------------------------------------------------
65+
66+
5967
/*!
6068
* 插入数据或更新数据
6169
* 如果没有表, 会自动创建表
@@ -84,15 +92,14 @@ NS_ASSUME_NONNULL_BEGIN
8492
*
8593
* insertedOrUpdatedValues : key 更新的这个模型对应的属性. value 属性 更新/新增 的模型, 可以是数组, 也可以是单个模型
8694
*/
87-
- (void)update:(id<SJDBMapUseProtocol>)model insertedOrUpdatedValues:(NSDictionary<NSString *, id> * __nullable)insertedOrUpdatedValues callBlock:(void (^)(BOOL))block;
95+
- (void)update:(id<SJDBMapUseProtocol>)model insertedOrUpdatedValues:(NSDictionary<NSString *, id> * __nullable)insertedOrUpdatedValues callBlock:(void (^)(BOOL result))block;
8896

8997
/*!
9098
* 此接口针对数组字段使用.
9199
* 如果数据库没有这个模型, 将不会保存
92100
*
93-
* deletedValues : key 更新的这个模型对应的属性(字段为数组). value 数组中删除掉的模型.
94101
*/
95-
- (void)updateTheDeletedValuesInTheModel:(id<SJDBMapUseProtocol>)model callBlock:(void (^)(BOOL))block;
102+
- (void)updateTheDeletedValuesInTheModel:(id<SJDBMapUseProtocol>)model callBlock:(void (^)(BOOL result))block;
96103

97104
@end
98105

SJDBMap/SJDatabaseMap.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ - (void)update:(id<SJDBMapUseProtocol>)model insertedOrUpdatedValues:(NSDictiona
208208
* 此接口针对数组字段使用.
209209
* 如果数据库没有这个模型, 将不会保存
210210
*
211-
* deletedValues : key 更新的这个模型对应的属性(字段为数组). value 数组中删除掉的模型.
212211
*/
213212
- (void)updateTheDeletedValuesInTheModel:(id<SJDBMapUseProtocol>)model callBlock:(void (^)(BOOL))block {
214213
[self addOperationWithBlock:^{

0 commit comments

Comments
 (0)