Skip to content

lzkkk/JLDatabase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JLDatabase

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

JLDatabase is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'JLDatabase'

LinkDB

example:

NSString *path = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];

NSString *name = [path stringByAppendingPathComponent:@"test.db"];
    
[[JLDatabaseManager defaultManager] linkDatabase:name];

create table

conforms to protocol JLDBManagerDelegate, and implement method:

#pragma mark JLDBManageDelegate
//NOT NULL, UNIQUE etc
+ (NSDictionary *)columnExtras{
    return @{@"email":@"NOT NULL",
             @"name":@"NOT NULL"
             };
}

//is blob in db
+ (BOOL)isBlobColumn:(NSString *)name {
    return [name isEqualToString:@"blob"];
}

// ignore key not in column
+ (BOOL)isIgnoreColumn:(NSString *)name {
    return [name isEqualToString:@"ignore"];
}

// primary keys
+ (NSArray *)columnPrimaryKey {
    return @[@"email", @"name"];
}

application

+ (NSArray *)queryAllData {
    return [[JLDatabaseManager defaultManager].database queryTableFromClazz:[JLTestEntity class] where:nil];
}

+ (BOOL)insertTestEntity:(JLTestEntity *)entity{
    return [[JLDatabaseManager defaultManager].database insertTableParameFromArray:@[entity] clazz:[JLTestEntity class] update:YES];
}

+ (BOOL)updateTestEntity:(JLTestEntity *)entity {
    return [[JLDatabaseManager defaultManager].database updateTableParameFromObj:entity where:[NSString stringWithFormat:@"WHERE email=%@ and  name =%@", entity.email, entity.name]];
}

+ (BOOL)deleteTestEntityByEmail:(NSString *)email name:(NSString *)name {
    return [[JLDatabaseManager defaultManager].database deleteTableParameFromClazz:[JLTestEntity class] where:[NSString stringWithFormat:@"WHERE email=%@ and name=%@", email, name]];
}

- (NSString *)description {
    return [NSString stringWithFormat:@"email: %@ \n name= %@ \n age: %zi \n newBee= %zi \n blob=%@ \n ignore=%@", self.email, self.name, self.age, self.newbee, self.blob, self.ignore];
}

use it is so easy!

Author

lzkkk, [email protected]

License

JLDatabase is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published