CJMDBUser
示例
要运行示例项目,请克隆仓库,并首先从 Example 目录运行 pod install
。
全局说明:
CJMDBUser 是基于 FMDB 的用户数据库管理 SDK。
实现的主要目的是解决多用户账号切换时的数据库管理和操作。
-
支持数据库字段增加等升级问题。
-
支持只对某些字段更新。
-
查询到数据直接转换为字典或数组。
-
支持分页查询等。
使用说明
- 初始化1
// 初始化1,dbName:默认是 default,mainDirectory:默认是 xx/Documents/com.cjm.db
_dbUser = [[CJMDBUser alloc] initWithDbName:@"user_101"
mainDirectory:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/CJMDB"]];
// 初始化2
_dbUser = [[CJMDBUser alloc] init];
// 修改数据库名称,默认是 default
_dbUser.dbName = @"user_102";
// 修改主目录,默认是 xx/Documents/com.cjm.db
_dbUser.mainDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/CJMDB2"];
- 创建表
// 创建表,SenderTableName:表名;SenderTableFields:表的字段定义
[_dbUser createTableAndInsertRecordIfNotExists:SenderTableName withTableFields:SenderTableFields];
- 删除表
// 删除表
[_dbUser dropTableAndDeleteRecordIfExists:SenderTableName];
- 插入数据
[_dbUser insertIntoTable:SenderTableName withValues:@{@"msg_id":@"1", @"msg":@"hello1", @"sender":@"101", @"peer":@"101", @"status":@0}];
- 更新数据
// 更新数据
[_dbUser updateTable:SenderTableName
withValues:@{@"msg_id":@"1", @"status":@1}
condition:[NSString stringWithFormat:@"msg_id=%@", CJMDBValue(@"1")]];
- 删除数据
// 删除数据
[_dbUser deleteFromTable:SenderTableName withCondition:[NSString stringWithFormat:@"msg_id=%@", CJMDBValue(@"1")]];
- 查询数据
NSArray *valuesArray = [_dbUser selectAllFromTable:SenderTableName
withCondition:[NSString stringWithFormat:@"msg_id=%@", CJMDBValue(@"1")]
order:@"msg_id ASC"
limit:@"1"];
版本更新
v0.1.0
第一个版本,实现了基础的增删改查功能。
推送podspec
pod repo push specs CJMDBUser.podspec --allow-warnings --sources=https://github.com/CocoaPods/Specs.git --use-libraries
使用安装
CJMDBUser 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile
pod "CJMDBUser"
作者
chenjm [email protected]
许可协议
CJMDBUser 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。