Skip to content

Commit

Permalink
增加了数据变化监听API.
Browse files Browse the repository at this point in the history
增加了数据变化监听API,支持增删改监听.
  • Loading branch information
huangzhibiao committed Mar 9, 2017
1 parent b7c422c commit 6cda255
Show file tree
Hide file tree
Showing 19 changed files with 1,191 additions and 330 deletions.
Binary file modified .DS_Store
Binary file not shown.
24 changes: 24 additions & 0 deletions BGFMDB.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
D76ADF551E5D678C00774585 /* file.txt in Resources */ = {isa = PBXBuildFile; fileRef = D76ADF541E5D678C00774585 /* file.txt */; };
D77587731E654CF3005295FC /* NSObject+BGModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D77587721E654CF3005295FC /* NSObject+BGModel.m */; };
D781DEBC1D9A5506007B6FB4 /* people.m in Sources */ = {isa = PBXBuildFile; fileRef = D781DEBB1D9A5506007B6FB4 /* people.m */; };
D78A0D7C1E70F92400511A6D /* stockController.m in Sources */ = {isa = PBXBuildFile; fileRef = D78A0D7A1E70F92400511A6D /* stockController.m */; };
D78A0D7D1E70F92400511A6D /* stockController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D78A0D7B1E70F92400511A6D /* stockController.xib */; };
D78A0D801E70F95700511A6D /* stockModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D78A0D7F1E70F95700511A6D /* stockModel.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -99,6 +102,11 @@
D77587721E654CF3005295FC /* NSObject+BGModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+BGModel.m"; sourceTree = "<group>"; };
D781DEBA1D9A5506007B6FB4 /* people.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = people.h; sourceTree = "<group>"; };
D781DEBB1D9A5506007B6FB4 /* people.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = people.m; sourceTree = "<group>"; };
D78A0D791E70F92400511A6D /* stockController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = stockController.h; sourceTree = "<group>"; };
D78A0D7A1E70F92400511A6D /* stockController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = stockController.m; sourceTree = "<group>"; };
D78A0D7B1E70F92400511A6D /* stockController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = stockController.xib; sourceTree = "<group>"; };
D78A0D7E1E70F95700511A6D /* stockModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = stockModel.h; sourceTree = "<group>"; };
D78A0D7F1E70F95700511A6D /* stockModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = stockModel.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -162,6 +170,7 @@
D70663101CD1EF67009E4B4D /* Supporting Files */,
D781DEBA1D9A5506007B6FB4 /* people.h */,
D781DEBB1D9A5506007B6FB4 /* people.m */,
D78A0D781E70F92400511A6D /* stockController */,
);
path = BGFMDB;
sourceTree = "<group>";
Expand Down Expand Up @@ -236,6 +245,18 @@
path = FMDB;
sourceTree = "<group>";
};
D78A0D781E70F92400511A6D /* stockController */ = {
isa = PBXGroup;
children = (
D78A0D791E70F92400511A6D /* stockController.h */,
D78A0D7A1E70F92400511A6D /* stockController.m */,
D78A0D7B1E70F92400511A6D /* stockController.xib */,
D78A0D7E1E70F95700511A6D /* stockModel.h */,
D78A0D7F1E70F95700511A6D /* stockModel.m */,
);
path = stockController;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -344,6 +365,7 @@
D70663201CD1EF67009E4B4D /* LaunchScreen.storyboard in Resources */,
D706631D1CD1EF67009E4B4D /* Assets.xcassets in Resources */,
D76ADF551E5D678C00774585 /* file.txt in Resources */,
D78A0D7D1E70F92400511A6D /* stockController.xib in Resources */,
D706631B1CD1EF67009E4B4D /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -375,12 +397,14 @@
D769F1A21E559F3700EDE420 /* BGTool.m in Sources */,
D70663151CD1EF67009E4B4D /* AppDelegate.m in Sources */,
D70663541CD1F10D009E4B4D /* FMDatabaseQueue.m in Sources */,
D78A0D7C1E70F92400511A6D /* stockController.m in Sources */,
D70663581CD1F144009E4B4D /* BGFMDB.m in Sources */,
D70663121CD1EF67009E4B4D /* main.m in Sources */,
D76ADF531E5D362300774585 /* BGModelInfo.m in Sources */,
D781DEBC1D9A5506007B6FB4 /* people.m in Sources */,
D70663511CD1F10D009E4B4D /* FMDatabase.m in Sources */,
D70663551CD1F10D009E4B4D /* FMResultSet.m in Sources */,
D78A0D801E70F95700511A6D /* stockModel.m in Sources */,
D70663521CD1F10D009E4B4D /* FMDatabaseAdditions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,5 @@
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "BGFMDB/ViewController.m"
timestampString = "510228081.925931"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "134"
endingLineNumber = "134"
landmarkName = "-viewDidLoad"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "BGFMDB/ViewController.m"
timestampString = "510228081.925931"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "119"
endingLineNumber = "119"
landmarkName = "-viewDidLoad"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "BGFMDB/ViewController.m"
timestampString = "510228081.925931"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "118"
endingLineNumber = "118"
landmarkName = "-viewDidLoad"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
Binary file modified BGFMDB/.DS_Store
Binary file not shown.
54 changes: 42 additions & 12 deletions BGFMDB/BGFMDB/BGFMDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@
为了对象层的事物操作而封装的函数.
*/
-(void)executeDB:(void (^_Nonnull)(FMDatabase *_Nonnull db))block;
/**
注册数据变化监听.
@name 注册名称,此字符串唯一,不可重复,移除监听的时候使用此字符串移除.
@return YES: 注册监听成功; NO: 注册监听失败.
*/
-(BOOL)registerChangeWithName:(NSString* const _Nonnull)name block:(ChangeBlock)block;
/**
移除数据变化监听.
@name 注册监听的时候使用的名称.
@return YES: 移除监听成功; NO: 移除监听失败.
*/
-(BOOL)removeChangeWithName:(NSString* const _Nonnull)name;

#pragma mark --> 以下是直接存储一个对象的API

/**
Expand Down Expand Up @@ -52,25 +65,28 @@
/**
根据keyPath查询对象
@cla 代表对应的类.
@keyPath 查询路径,形式 @"user.student.name"
@value 值,@"小芳"
说明: 即查询 user.student.name=小芳 的对象数据.
@keyPathValues数组,形式@[@"user.student.name",Equal,@"小芳",@"user.student.conten",Contains,@"书"]
即查询user.student.name等于@"小芳" 和 user.student.content中包含@“书”这个字符串的对象.
*/
-(void)queryObjectWithClass:(__unsafe_unretained _Nonnull Class)cla forKeyPath:(NSString* _Nonnull)keyPath value:(id _Nonnull)value complete:(Complete_A)complete;
-(void)queryObjectWithClass:(__unsafe_unretained _Nonnull Class)cla forKeyPathAndValues:(NSArray* _Nonnull)keyPathValues complete:(Complete_A)complete;
/**
根据条件改变对象的所有变量值.
根据条件改变对象数据.
@object 要更新的对象.
@where 数组的形式 @[@"key",@"=",@"value",@"key",@">=",@"value"],为nil时设置全部.
目前不支持keypath的key,即嵌套的自定义类, 形式如@[@"user.name",@"=",@"习大大"]暂不支持
@complete 回调的block
*/
-(void)updateWithObject:(id _Nonnull)object where:(NSArray* _Nullable)where complete:(Complete_B)complete;
/**
根据keyPath改变对象数据.
@keyPathValues数组,形式@[@"user.student.name",Equal,@"小芳",@"user.student.conten",Contains,@"书"]
即更新user.student.name=@"小芳" 和 user.student.content中包含@“书”这个字符串的对象.
*/
-(void)updateWithObject:(id _Nonnull)object forKeyPathAndValues:(NSArray* _Nonnull)keyPathValues complete:(Complete_B)complete;
/**
根据条件改变对象的部分变量值.
@cla 代表对应的类.
@valueDict 存放的是key和value 即@{key:value,key:value}..
@where 数组的形式 @[@"key",@"=",@"value",@"key",@">=",@"value"],为nil时设置全部.
目前不支持keypath的key,即嵌套的自定义类, 形式如@[@"user.name",@"=",@"习大大"]暂不支持
@complete 回调的block
*/
-(void)updateWithClass:(__unsafe_unretained _Nonnull Class)cla valueDict:(NSDictionary* _Nonnull)valueDict where:(NSArray* _Nullable)where complete:(Complete_B)complete;
Expand Down Expand Up @@ -144,11 +160,10 @@
/**
keyPath查询.
@name 表名称.
@keyPath 查询路径,形式 @"user.student.name"
@value 值,@"小芳"
说明: 即查询 user.student.name=小芳 的对象数据.
@keyPathValues数组,形式@[@"user.student.name",Equal,@"小芳",@"user.student.conten",Contains,@"书"]
即查询user.student.name=@"小芳" 和 user.student.content中包含@“书”这个字符串的对象.
*/
-(void)queryWithTableName:(NSString* _Nonnull)name forKeyPath:(NSString* _Nonnull)keyPath value:(id _Nonnull)value complete:(Complete_A)complete;
-(void)queryWithTableName:(NSString* _Nonnull)name forKeyPathAndValues:(NSArray* _Nonnull)keyPathValues complete:(Complete_A)complete;
/**
更新数据.
@name 表名称.
Expand All @@ -157,13 +172,27 @@
@complete 回调的block.
*/
-(void)updateWithTableName:(NSString* _Nonnull)name valueDict:(NSDictionary* _Nonnull)valueDict where:(NSArray* _Nullable)where complete:(Complete_B)complete;
/**
根据keypath更新数据.
@name 表名称.
@keyPathValues数组,形式@[@"user.student.name",Equal,@"小芳",@"user.student.conten",Contains,@"书"]
即更新user.student.name=@"小芳" 和 user.student.content中包含@“书”这个字符串的对象.
*/
-(void)updateWithTableName:(NSString* _Nonnull)name forKeyPathAndValues:(NSArray* _Nonnull)keyPathValues valueDict:(NSDictionary* _Nonnull)valueDict complete:(Complete_B)complete;
/**
根据表名和条件删除表内容.
@name 表名称.
@where 条件数组,形式 @[@"key",@"=",@"value",@"key",@">=",@"value"],where要非空,条件key属性只能是系统自带的属性,暂不支持自定义类.
@where 条件数组,形式 @[@"key",@"=",@"value",@"key",@">=",@"value"],where要非空.
@complete 回调的block.
*/
-(void)deleteWithTableName:(NSString* _Nonnull)name where:(NSArray* _Nonnull)where complete:(Complete_B)complete;
/**
根据keypath删除表内容.
@name 表名称.
@keyPathValues数组,形式@[@"user.student.name",Equal,@"小芳",@"user.student.conten",Contains,@"书"]
即删除user.student.name=@"小芳" 和 user.student.content中包含@“书”这个字符串的对象.
*/
-(void)deleteWithTableName:(NSString* _Nonnull)name forKeyPathAndValues:(NSArray* _Nonnull)keyPathValues complete:(Complete_B)complete;
/**
根据表名删除表格全部内容.
@name 表名称.
Expand All @@ -189,6 +218,7 @@
@where 条件数组,形式 @[@"key",@"=",@"value",@"key",@">=",@"value"],为nil时返回全部数据的条数.
*/
-(NSInteger)countForTable:(NSString* _Nonnull)name where:(NSArray* _Nullable)where;
-(NSInteger)countForTable:(NSString* _Nonnull)name forKeyPathAndValues:(NSArray* _Nonnull)keyPathValues;
/**
刷新数据库,即将旧数据库的数据复制到新建的数据库,这是为了去掉没用的字段.
@name 表名称.
Expand Down
Loading

0 comments on commit 6cda255

Please sign in to comment.