Skip to content

Commit

Permalink
Update [ Update methods Added Alert Fields ]
Browse files Browse the repository at this point in the history
  • Loading branch information
changsanjiang committed Sep 5, 2017
1 parent 8467168 commit 66b4db0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion SJDBMap.podspec
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 6 additions & 0 deletions SJDBMap/Category/SJDatabaseMap+Server.m
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ - (BOOL)sjUpdate:(id<SJDBMapUseProtocol>)model property:(NSArray<NSString *> *)f

[self _sjBeginTransaction];

[self sjCreateOrAlterTabWithClass:[model class]];

// 查看是否有特殊字段
NSDictionary<NSString *, NSArray<NSString *> *> *putInOrderResult = [self _sjPutInOrderModel:model fields:fields];

Expand Down Expand Up @@ -497,10 +499,12 @@ - (BOOL)_sjUpdate:(id<SJDBMapUseProtocol>)model uniqueFields:(NSArray<NSString *
// is Arr
if ( [uniqueValue isKindOfClass:[NSArray class]] ) {
// insert arr values
[self sjCreateOrAlterTabWithClass:[[uniqueValue firstObject] class]];
result = [self sjInsertOrUpdateDataWithModels:uniqueValue enableTransaction:NO];
return;
}
// is cor
[self sjCreateOrAlterTabWithClass:[uniqueValue class]];
if ( result ) result = [self sjInsertOrUpdateDataWithModel:uniqueValue uM:[self sjGetUnderstandingWithClass:[uniqueValue class]]];
}];

Expand Down Expand Up @@ -575,12 +579,14 @@ - (BOOL)sjUpdate:(id<SJDBMapUseProtocol>)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;}
}];
Expand Down
13 changes: 10 additions & 3 deletions SJDBMap/SJDatabaseMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ NS_ASSUME_NONNULL_BEGIN

@interface SJDatabaseMap (InsertOrUpdate)


// MARK: ---------------------------------------------------------
/*!
* 数据库依据模型来存储. 所以在存储之前, 请将模型更新到最新状态, 再进行存储.
*/
// MARK: ---------------------------------------------------------


/*!
* 插入数据或更新数据
* 如果没有表, 会自动创建表
Expand Down Expand Up @@ -84,15 +92,14 @@ NS_ASSUME_NONNULL_BEGIN
*
* insertedOrUpdatedValues : key 更新的这个模型对应的属性. value 属性 更新/新增 的模型, 可以是数组, 也可以是单个模型
*/
- (void)update:(id<SJDBMapUseProtocol>)model insertedOrUpdatedValues:(NSDictionary<NSString *, id> * __nullable)insertedOrUpdatedValues callBlock:(void (^)(BOOL))block;
- (void)update:(id<SJDBMapUseProtocol>)model insertedOrUpdatedValues:(NSDictionary<NSString *, id> * __nullable)insertedOrUpdatedValues callBlock:(void (^)(BOOL result))block;

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

@end

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

0 comments on commit 66b4db0

Please sign in to comment.