登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

一行代码搞定数据库

[复制链接]
来自: masong 分类: iOS精品源码 上传时间: 2017-8-9 16:17:16
Tag:

项目介绍:

github连接 https://github.com/masong2012/DBAssistant

Getting started

add pod ‘DBAssistant’ to your Podfile
run pod install
import "NSObject+DB.h"
Example

create a file user.h

@interface User : NSObject
@property (strong, nonatomic) NSString *name;
@property (assign, nonatomic) CGFloat height;
@property (assign, nonatomic) NSInteger num;
@end
use the User model where you need

//create a new model
User *user = [[User alloc]init];
user.name = @"mason";
user.height = 180.23;
user.num = 123456;
[user saveModel];

NSLog(@"users count: %ld",User.allModels.count);

//find model
user = [User firstModelWhere:@{DBRowId: @(1)}];
NSLog(@"name %@,num: %ld,height: %lf",user.name,user.num,user.height);

//update model
[user updateModel:@{@"name": @"Dear"}];

user = [User firstModelWhere:@{DBRowId: @(1)}];
NSLog(@"name %@,num: %ld,height: %lf",user.name,user.num,user.height);

//delete model
[user deleteModel];
NSLog(@"users count: %ld",User.allModels.count);

More Interfaces

Configs

//dbPath
+(NSString*)dbPath;

//tableName,default is the current class
+(NSString*)tableName;

//primarykeys,default is DBRowID
+(NSArray*)primaryKeys;

//only properties to map table columns
+(NSArray *)onlyPropertiesToMapColumns;

//except properties to map table columns
+(NSArray *)exceptPropertiesToMapColumns;

//property to column Mappings
+(NSDictionary *)propertyToColumnMappings;

//properties default values
+(NSDictionary *)defaultValues;

//properties value check values
+(NSDictionary *)checkValues;

//properties value length
+(NSDictionary *)lengthValues;

//properties value those should be unique
+(NSArray *)uniqueValues;

//properties value those should be not null
+(NSArray *)notNullValues;

+(NSString *)dateFormatterString;

+(NSString )imagePathForImage:(NSString )imgName ;

+(NSString )dataPathForData:(NSString )dataName;

//default is YES
+(BOOL)shouldMapAllParentPropertiesToTable;

//default is YES
+(BOOL)shouldMapAllSelfPropertiesToTable;

Create/Drop table

+(BOOL)createTable;

+(BOOL)dropTable;
Insert

+(BOOL)insertModel:(NSObject *)model;

+(BOOL)insertModelIfNotExists:(NSObject *)model;

-(BOOL)saveModel;
Update

+(BOOL)updateModelsWithModel:(NSObject )model where:(NSObject )where;

+(BOOL)updateModelsWithDictionary:(NSDictionary )dic where:(NSObject )where;

-(BOOL)updateModel:(id)value;
Find

+(BOOL)modelExists:(NSObject *)model;

+(NSArray *)allModels;

+(NSArray )findModelsBySQL:(NSString )sql;

+(NSArray )findModelsWhere:(NSObject )where;

+(NSArray )findModelsWhere:(NSObject )where orderBy:(NSString *)orderBy;

+(NSArray )findModelsWhere:(NSObject )where groupBy:(NSString )groupBy orderBy:(NSString)orderBy limit:(int)limit offset:(int)offset;

+(id)firstModelWhere:(NSObject *)where;

+(id)firstModelWhere:(NSObject )where orderBy:(NSString)orderBy ;

+(id)lastModel;

+(NSInteger)rowCountWhere:(NSObject *)where;
Delete

+(BOOL)deleteModel:(NSObject *)model;

+(BOOL)deleteModelsWhere:(NSObject *)where;

-(BOOL)deleteModel;
Transaction

+(void)beginTransaction;

+(void)commit;

+(void)rollback;

相关源码推荐:

我来说两句
*滑动验证:
所有评论(12)
逆鳞九霄 2017-8-10 14:13:48
强烈支持楼主ing……
回复
hellokenken 2017-8-10 14:14:32
虽不明,但觉厉...
回复
AlonMessi 2017-8-10 14:14:51
不错不错,楼主辛苦了。。。
回复
phoiu 2017-8-10 14:15:22
code4app好的代码demo真的很多,谢谢啦~
回复
littleRed 2017-8-10 14:16:03
感谢分享,楼主V5~
回复
kengsir 2017-8-10 14:17:00
mark,收藏了
回复
BlueManlove 2017-8-10 14:17:37
感谢大神~
回复
ChangeOneself 2017-8-10 16:44:40
正需要啊,感谢楼主无私分享!
回复
code4app热心网友 2017-8-11 01:15:09
精华内容,楼主V5!
回复
12下一页
提取码:  下载次数:26 状态:已购或VIP 售价:0(原价:0)金钱 下载权限:初级码农 
1118 0 26
联系我们
首页/微信公众账号投稿

帖子代码编辑/版权问题

QQ:435399051,742864542

如何获得代码达人称号?

代码贡献英雄榜
用户名 下载数
通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| 广东互联网违法和不良信息举报中心|中国互联网举报中心|Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

快速回复 返回顶部 返回列表
博聚网