原理

iOS 和 SQL的相应关系

Model类结构      =>    SQL表结构

Model实例       =>  SQL表中的一行

Model实例的属性   =>   SQL表中的一列

Model和Table的相应

@interface TestModel :NSObject

@property (assign, nonatomic) NSInteger age;
@property (assign, nonatomic) CGFloat height;
@property (assign, nonatomic) long distance;
@property (assign, nonatomic) double maxDistance;
@property (assign, nonatomic) BOOL isOK;
@property (assign, nonatomic) char mChar; @property (assign, nonatomic) CGRect rect;
@property (assign, nonatomic) CGPoint point;
@property (assign, nonatomic) CGSize size;
@property (assign, nonatomic) NSRange range; @property (strong, nonatomic) NSNumber *number;
@property (strong, nonatomic) NSString *string;
@property (strong, nonatomic) UIColor *color;
@property (strong, nonatomic) NSDate *date; @property (strong, nonatomic) NSData *data;// convert to data
@property (strong, nonatomic) NSValue *value;
@property (strong, nonatomic) UIImage *image; @end

相应的表结构就是 TABLE TestModel (age type,height type,distance type,isOK type,mChar type,...)

方法

以下是一些可用的方法,还在完好中。。。

+(ModelToTableMap*)getModelToTableMap;

+(NSString*)getDBPath;
+(NSString*)getTableName;
+(NSArray*)getPrimaryKeys; +(NSDictionary *)getPropertyToColumnMap;
+(NSDictionary *)getDefaultValueDictionary;
+(NSDictionary *)getLengthDictionary;
+(NSDictionary *)getCheckValueDictionary;
+(NSDictionary *)getIsUniqueDictionary;
+(NSDictionary *)getIsNotNullDictionary; +(BOOL)shouldModelToTableMapContainParentProperties;
+(BOOL)shouldModelToTableMapContainSelfProperties; +(NSString *)getDateFormatterString;
+(NSString *)getDBImagePathWithImageName:(NSString *)imgName ;
+(NSString *)getDBDataPathWithDataName:(NSString *)dataName; +(BOOL)createTable; +(BOOL)dropTable; +(id)firstModelWhere:(NSObject *)where;
+(id)firstModelWhere:(NSObject *)where orderBy:(NSString*)orderBy ; +(NSArray *)allModels;
+(NSArray *)findModelsWhere:(NSObject *)where;
+(NSArray *)findModelsWhere:(NSObject *)where orderBy:(NSString*)orderBy offset:(int)offset count:(int)count; +(BOOL)insertModel:(NSObject *)model;
+(BOOL)insertModelWhenNotExists:(NSObject *)model; +(BOOL)deleteModel:(NSObject *)model;
+(BOOL)deleteModelsWhere:(NSObject *)where; +(BOOL)updateModelsWithModel:(NSObject *)model where:(NSObject *)where;
+(BOOL)updateModelsWithDictionary:(NSDictionary *)dic where:(NSObject *)where; +(BOOL)isModelExists:(NSObject *)model; - (BOOL)saveModel;
- (BOOL)deleteModel;
- (BOOL)updateModel:(NSObject *)theNewModel;
- (BOOL)updateModelWithDictionary:(NSDictionary *)dic;

使用

TestModel *model = [[TestModel alloc] init];
model.age = 20;
model.image = [UIImage imageNamed:@"img.jpg"];
//添加
[model saveModel]
//删除
[model deleteModel]
//改动
[model updateModelWithDictionary:@{@"age":@(21)}]
//查找
[TestModel allModels]

下载地址:点这里

最新文章

  1. 【转载】Fiddler进行模拟Post提交json数据,总为null解决方式
  2. WebAPI身份验证
  3. 查看linux库文件32位还是64位
  4. paper 14 : 图像视觉领域部分开源代码
  5. visualvm添加远程管理-centos
  6. 通过jquery 获取文本框的聚焦和失焦方法
  7. 在win7系统下使用TortoiseGit(乌龟git)简单操作Git@OSC
  8. C++学习笔记(六):复杂数据类型(string、容器和STL)
  9. Linux远程登录
  10. hdu 5649 DZY Loves Sorting 二分+线段树
  11. 用angularjs开发下一代web应用(二):angularjs应用骨架(二)
  12. MySQL分区表与合并表
  13. MongoDB个人简单总结
  14. 20172328 2018-2019《Java软件结构与数据结构》第四周学习总结
  15. Linux之恢复误删的文件[针对丢弃到回收站]
  16. k8s官网 基础知识入门教程
  17. Centos7部署kubernetes-ETCD集群(三)
  18. Hibernate对substring和cast的支持问题
  19. ABAP-金额小写转大写
  20. UI5-学习篇-2-Hello World

热门文章

  1. python之set集合及深浅拷贝
  2. 学习c语言的感想
  3. Mysql中的索引()key 、primary key 、unique key 与index区别)
  4. P3368 【模板】树状数组 2(树状数组维护差分序列)
  5. 易语言 打开exe可执行文件、打开网页
  6. [文章转载]-我的Java后端书架-江南白衣
  7. js的replace, 高亮
  8. Scala 技术笔记之 Option Some None
  9. Netty 长连接服务
  10. 数据结构与算法(5) -- deque