iOS5 及以后
规则:
列名是类的成员名称。
例如
// class
@interface GXBaseMessage : NSObject {
NSString *address;
}
@property (nonatomic, assign) NSInteger count;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSMutableArray *datas;
@end
成员名称 | 列名 |
---|---|
address | address |
count | _count |
name | _name |
datas | - |
<catagory>
NSObject+serializable
<src>
GXDatabaseManager
GXSQLStatementManager
GXCache
C-创建
R-检索
U-更新
D-删除
NSString *dbPath = [NSHomeDirectory() stringByAppendingPathComponent:@"testDB.sqlite"];
BOOL res = [GXDatabaseManager databaseWithPath:dbPath];
res = [GXDatabaseManager createTable:@"t_message" withClass:[GXMessage class] withPrimaryKey:@"_msgId"];
NSString *dbPath = [[NSBundle mainBundle] pathForResource:@"db" ofType:@"sqlite"];
BOOL res = [GXDatabaseManager databaseWithPath:dbPath];
if (!res) {
NSLog(@"ERROR...");
}
NSString *w1 = kWhereString(@"_sessionUserid", @"=");
NSString *w2 = kWhereString(@"_msgId", @"=");
NSString *w = kWhereCombination(w1, @"AND", w2);
[GXDatabaseManager selectObjects:[GXMessageDBEntity class]
fromTable:@"t_message_chat"
where:w
withParams:@[@"1525851662", @"615734ef-2db1-427a-9505-b49ec6a8628c"]
orderBy:@"_msgTime"
withSortType:@"DESC"
withRange:NSMakeRange(0, 5)];
// replace into
NSString *dbPath = [NSHomeDirectory() stringByAppendingPathComponent:@"testDB.sqlite"];
BOOL res = [GXDatabaseManager databaseWithPath:dbPath];
// create table
res = [GXDatabaseManager createTable:@"t_message" withClass:[GXMessage class] withPrimaryKey:@"_msgId"];
[GXDatabaseManager replaceInto:@"t_message" withObject:msg];
// update
NSString *dbPath = [NSHomeDirectory() stringByAppendingPathComponent:@"testDB.sqlite"];
BOOL res = [GXDatabaseManager databaseWithPath:dbPath];
if (!res) NSLog(@"ERROR");
NSString *w = kWhereString(@"_msgId", @"=");
[GXDatabaseManager updateTable:@"t_message"
set:@[@"_fontName"]
where:w
withParams:@[@"黑体", @"1ccaf308-8bb0-1e44-2f0b-98f308d03d57"]];
NSString *dbPath = [[NSBundle mainBundle] pathForResource:@"db" ofType:@"sqlite"];
BOOL res = [GXDatabaseManager databaseWithPath:dbPath];
if (!res) NSLog(@"ERROR...");
[GXDatabaseManager deleteTable:@"t_message_chat" where:@"_msgId=?" withParams:@[@"1ccaf308-8bb0-1e44-2f0b-98f308d03d57"]];
GXDatabaseUtils 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。