关于iOS GYDataCenter本地数据库解决方案的那些事儿--下卷

本文继上篇介绍了GYDataCenter在iOS中的应用后,重点讨论了数据库操作的核心部分——增删查改。针对查询的高效性、数据更新策略以及删除操作的逻辑与物理删除进行了深入探讨,并提到了特殊字符在查询中的转译问题。
摘要由CSDN通过智能技术生成

之前的博客讲解了如何保存用户的敏感信息和如何使用GYDataCenter创建数据库和数据表,这一篇主要谈一谈在开发中经常用的增删查改解决方案。

3.如何进行增删查改

先来查看一下GY的头文件,在GYDataCenter.h里面只有两个头文件。
这里我们就知道了,外部主要使用的就只有GYDataContent和GYModelObject这两个类的内容,上一次在创建表格的时候就是继承了GYModelObject,从字面上理解,我们的数据库操作就应该属于GYDataContext的内容了。
#import <Foundation/Foundation.h>

#import "GYDBRunner.h"

@protocol GYModelObjectProtocol;

@interface GYDataContext : NSObject

+ (GYDataContext *)sharedInstance;

/**
 *
 * @param modelClass Class of the model object that you want to fetch.
 *	需要查询的数据类型,在这里就是需要操作的数据表
 * @param properties Properties you need. Pass nil to get values of all properties.
 *	需要查询的表格中的字段,如果传入空的Array,返回所有的属性
 * @param primaryKey Primary key value of the model object that you want to fetch.
 *	需要查询的数据的主键
 * @return Object that match the primary key value, or nil if none is found.
 *	返回传入的表格的对象,对象内持有传入的字段的值
 */

- (id)getObject:(Class<GYModelObjectProtocol>)modelClass
     properties:(NSArray *)properties
     primaryKey:(id)primaryKey;

/**
 *
 * @param modelClass Class of the model objects that you want to fetch.
 *	需要查询的数据类型,在这里就是需要操作的数据表
 * @param properties Properties you need. Pass nil to get values of all properties.
 *	需要查询的表格中的字段,如果传入空的Array,返回所有的属性
 * @param where Where clause of SQL. Use '?'s as placeholders for arguments.
 *	这里传入SQL语句,格式为“where........” 这里是SQL中的条件语句
 * @param arguments Values to bind to the where clause.
 *	上述SQL语句对应的Value
 * @return Objects that match the condition of the where clause.
 *	返回传入的表格的对象,对象内持有传入的字段的值
 */

- (NSArray *)getObjects:(Class<GYModelObjectProtocol>)modelClass
             properties:(NSArray *)properties
                  where:(NSString *)where
              arguments:(NSArray *)arguments;

/** Join two tables.
 *	连标查询
 * @param leftClass Class of the first join table.
 *	第一个关联的表格,一般为父表
 * @param leftProperties Properties of leftClass that you need. Pass nil to get values of all properties.
 *	第一个表格的字段,一般为父表的字段,如果传入空的Array,返回所有的属性
 * @param rightClass Class of the second join table.
 *	关联的第二个表格,一般为子表
 * @param rightProperties Properties of rightClass that you need. Pass nil to get values of all properties.
 *	关联的字表的字段,一般为字表的字段, 如果传入空的Array,返回所有的属性
 * @param joinType GYSQLJoinTypeInner, GYSQLJoinTypeLeft or GYSQLJoinTypeCross.
 *	两个表关联的方式
 * @param joinCondition Join condition. For example: 'leftTableName.property1 = rightTableName.property2'.
 *	关联的字段
 * @param where Where clause of SQL. Use '?'s as placeholders for arguments.
 *	这里传入SQL语句,格式为“where........” 这里是SQL中的条件语句
 * @param arguments Value
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值