TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | Custom |
ReleasedLast Release | Jun 2016 |
Maintained by Valo Lee.
pod 'FMDB'
删掉pod 'VODBCache','2.0.0'
VODBCache
文件夹的所有源码拽入项目#import "VDCache.h"
1.配置
.1) 可不配置vd_myCls,使用spec的代码中会自动设置为当前类名
.2) 每个对象必须要有唯一性约束,所以必须配置vd_classSpec的vd_primaryKey 或者实现- (NSString *)vd_generatePrimaryKey
两者之一
+ (VDClassSpec *)vd_classSpec{
return [VDClassSpec vd_makeClassSpecWithBlock:^(VDClassSpec *spec) {
spec.vd_primaryKey(@"citycode") //主键名,将使用此属性的值作为唯一性约束
.vd_cacheBlackList(@[@"WD",@"WS"]); //黑名单
}];
}
- (NSString *)vd_generatePrimaryKey{ //配置唯一性约束的另一种方式
return self.userId;
}
2.增删改查的使用请查看注释. sqlWhere表示SQL语句的Where(查询条件)部分, sqlSort表示SQL语句的ORDER BY(排序)部分,sqlRange表示SQL语句的LIMIT部分
BOOL ret = [weather vd_cacheObject];
BOOL ret = [weather vd_cacheOrUpdateObject];
BOOL ret = [VOWeather vd_cacheOrUpdateOObjects:array];
self.weathers = [VOWeather vd_queryCachedObjectsWhere:nil sort:nil range:NSMakeRange(0, 100)];
NSString *condition = [NSString stringWithFormat:@"\"pinyin\" = \"%@\"",city];
BOOL ret = [VOWeather vd_deleteCachedObjectsWhere:condition];
BOOL ret = [VOWeather vd_deleteCachedObjects:willDelArray];
NSString *condition = [NSString stringWithFormat:@"\"pinyin\" = \"%@\"",city];
NSString *lTmp = self.lTmpTextField.text;
NSString *hTmp = self.hTmpTextField.text;
NSString *tmp = self.tmpTextField.text;
NSMutableString *values = [NSMutableString string];
if (lTmp && lTmp.length > 0) {
[values appendFormat:@"\"l_tmp\" = \"%@\",",lTmp];
}
if (hTmp && hTmp.length > 0) {
[values appendFormat:@"\"h_tmp\" = \"%@\",",hTmp];
}
if (tmp && tmp.length > 0) {
[values appendFormat:@"\"temp\" = \"%@\",",tmp];
}
if (values.length < 2) {
NSLog(@"No value to modify");
return;
}
[values deleteCharactersInRange:NSMakeRange(values.length - 1, 1)];
NSString *tableName = NSStringFromClass([VOWeather class]);
if (VDCache.tablePrefix.length > 0 && ![tableName isEqualToString:NSStringFromClass([VDClassSpec class])]) {
tableName = [VDCache.tablePrefix stringByAppendingString:tableName];
}
NSString *sql = [NSString stringWithFormat:@"UPDATE \"%@\" SET %@ WHERE %@", tableName, values, condition];
BOOL ret = [VOWeather vd_excuteWithSQL:sql];
3.如运行时候,出现如下错误:
(19: UNIQUE constraint failed: weather.vd_primaryKey)
此错误说明唯一性冲突,一般可忽略.
4.设置数据库文件加密密钥(2.0.0-beta11):
[VDCache setEncryptKey:@"123456"];
5.可使用[VDCache setLogErrors:YES];
打开关闭数据库调试信息
欢迎大家多提issue.