LevelDB Wrapper with simple api
- PBCoding Serialization
- Common Type Key-Value API
- DBError Function LevelDBSetErrorFunction
-
CocoaPods Embbed `pod 'LevelStorage'
-
Project Config
// config error function
LevelDBSetErrorFunction(^(NSString* name, NSError* error){
if (error.code == LevelDBOpenError) {
NSString* kvPath = [LevelKV pathWithNameSpace:name];
[[NSFileManager defaultManager] removeItemAtPath:kvPath error:nil];
}else if (error.code == LevelDBSetError){
}else if (error.code == LevelDBGetError){
}else if (error.code == LevelDBDeleteError){
}
});
// init
LevelKV* kv = [LevelKV keyValueWithNameSpace:@"com.tencent.leveldb.weread"];
// api
[kv setInt32:123456 forKey:@"count"];
NSInteger count = [kv getInt32ForKey:@"count"];
/**
non-threadsafe set kv api
*/
- (BOOL)setObject:(id<LevelCoding>)obj forKey:(NSString*)key;
- (BOOL)setBool:(bool)value forKey:(NSString*)key;
- (BOOL)setInt32:(int32_t)value forKey:(NSString*)key;
- (BOOL)setString:(NSString*)value forKey:(NSString*)key;
- (BOOL)setData:(NSData*)value forKey:(NSString*)key;
- (BOOL)setJSONObject:(id)JSON forKey:(NSString *)key; //JSON
/**
non-threadsafe get kv api
*/
- (id)getObjectOfClass:(Class)cls forKey:(NSString*)key;
- (bool)getBoolForKey:(NSString*)key;
- (bool)getBoolForKey:(NSString*)key defaultValue:(bool)defaultValue;
- (int32_t)getInt32ForKey:(NSString*)key;
- (int32_t)getInt32ForKey:(NSString*)key defaultValue:(int32_t)defaultValue;
- (NSString*)getStringForKey:(NSString*)key;
- (NSString*)getStringForKey:(NSString*)key defaultValue:(NSString*_Nullable)defaultValue;
- (NSData*)getDataForKey:(NSString*)key;
- (NSData*)getDataForKey:(NSString*)key defaultValue:(NSString*_Nullable)defaultValue;
- (id)getJSONObjectForKey:(NSString *)key; //JSON
#pragma mark - Removers
- (void)removeObjectForKey:(NSString*)key;
- (void)removeObjectsForKeys:(NSArray*)keys;
#pragma mark - Checker
- (BOOL)existsValueForKey:(NSString *)key;