0%

EFFMDBTool/EFFMDBTool.h

Supporting Files/EFFMDBTool/EFFMDBTool.h

一个简单易用的基于 FMDB的sqlite数据库工具。

一般 [这是什么?]

2.0~[这是什么?]

+sharedTool

创建 MDB 实例,如果数据库不存在会自动创建,数据库名 MDBName 在 AppConfig 配置。(Get instance of EFFMDBTool, create database named in AppConfig if not exist.)

参数:

返回值:

EFFMDBTool EFFMDBTool实例,不为空。

-mdb

FMDatabase 实例,通过方法获取。(Get instance of FMDatabase with method style.)

参数:

返回值:

FMDatabase FMDatabase实例,不为空。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
FMDatabase 实例
*/
@property (strong, nonatomic, nonnull) FMDatabase *mdb;

/**
创建 MDB 实例,如果数据库不存在会自动创建,数据库名 MDBName 在 AppConfig 配置。(Get instance of EFFMDBTool, create database named in AppConfig if not exist.)

@return EFFMDBTool 实例
*/
+ (instancetype)sharedTool;

/**
FMDatabase 实例,通过方法获取。(Get instance of FMDatabase with method style.)

@return FMDatabase 实例
*/
- (FMDatabase *)mdb;

[这是什么?]

数据库操作 Database open, close, …

2.0~

-canOpen_mdb

打开数据库是否成功。(Open the database successed or not.)

参数:

返回值:

BOOL 操作执行结果,YES 成功 NO 失败。

-close_mdb

关闭数据库。(Close the database.)

参数:

返回值:

-tableExistsWithModel:

Model(基于 BaseDataModel) 对应的表是否已创建。(The table named of the model’s name based on BaseDataModel was created or not.)

参数:

cls Model(基于 BaseDataModel) 的类,必填 Class

返回值:

BOOL 检查结果,YES 已创建,NO 未创建。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//MARK: - 数据库操作 Database open, close, ...
/**
打开数据库是否成功。(Open the database successed or not.)

@return 操作执行结果,YES 成功 NO 失败
*/
- (BOOL)canOpen_mdb;

/**
关闭数据库。(Close the database.)
*/
- (void)close_mdb;

/**
Model(基于 BaseDataModel) 对应的表是否已创建。(The table named of the model's name based on BaseDataModel was created or not.)

@param cls Class of model based on BaseDataModel
@return 检查结果,YES 已创建,NO 未创建
*/
- (BOOL)tableExistsWithModel:(Class)cls;

解析 SQL 方法 Get the SQL String

2.0~

-query:

解析为 SELECT SQL,提供 model(基于 BaseDataModel) 的类 。(Get the SQL like “SELECT * FROM modelName” with class of a model based on BaseDataModel.)

参数:

cls Model(基于 BaseDataModel) 的类,必填 Class

返回值:

NSString 需要执行的SQL语句,不为空。

-query:dataID:

解析为 SELECT SQL,提供 model(基于 BaseDataModel) 的类和 dataID。(Get the SQL like “SELECT * FROM modelName WHERE modelName_dataID = 99” with class and dataID of a model based on BaseDataModel.)

参数:

cls Model(基于 BaseDataModel) 的类,必填 Class
dataID Model(基于 BaseDataModel) 的dataID,必填 NSInteger

返回值:

NSString 需要执行的SQL语句,不为空。

-query:dataName:

解析为 SELECT SQL,提供 model(基于 BaseDataModel) 的类和 dataName。(Get the SQL like “SELECT * FROM modelName WHERE modelName_dataName = ‘Color’” with class and dataName of a model based on BaseDataModel.)

参数:

cls Model(基于 BaseDataModel) 的类,必填 Class
dataName Model(基于 BaseDataModel) 的dataName,必填 NSString

返回值:

NSString 需要执行的SQL语句,不为空。

-remove:dataID:

解析为 DELETE SQL,提供 model(基于 BaseDataModel) 的类和 dataID。(Get the SQL like “DELETE FROM modelName WHERE modelName_dataID = 99” with class and dataID of a model based on BaseDataModel.)

参数:

cls Model(基于 BaseDataModel) 的类,必填 Class
dataID Model(基于 BaseDataModel) 的dataID,必填 NSInteger

返回值:

NSString 需要执行的SQL语句,不为空。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//MARK: - 解析 SQL 方法
/**
解析为 SELECT SQL,提供 model(基于 BaseDataModel) 的类。(Get the SQL like "SELECT * FROM modelName" with class of a model based on BaseDataModel.)

@param cls Class of model based on BaseDataModel
@return sql string
*/
- (NSString *)query:(Class _Nonnull)cls;
/**
解析为 SELECT SQL,提供 model(基于 BaseDataModel) 的类和 dataID。(Get the SQL like "SELECT * FROM modelName WHERE modelName_dataID = 99" with class and dataID of a model based on BaseDataModel.)

@param cls Class of model based on BaseDataModel
@param dataID "dataID" of model based on BaseDataModel
@return sql string
*/
- (NSString *)query:(Class _Nonnull)cls dataID:(NSInteger)dataID;
/**
解析为 SELECT SQL,提供 model(基于 BaseDataModel) 的类和 dataName。(Get the SQL like "SELECT * FROM modelName WHERE modelName_dataName = 'Color'" with class and dataName of a model based on BaseDataModel.)

@param cls Class of model based on BaseDataModel
@param dataName "dataName" of model based on BaseDataModel
@return sql string
*/
- (NSString *)query:(Class _Nonnull)cls dataName:(NSString *)dataName;
/**
解析为 DELETE SQL,提供 model(基于 BaseDataModel) 的类和 dataID。(Get the SQL like "DELETE FROM modelName WHERE modelName_dataID = 99" with class and dataID of a model based on BaseDataModel.)

@param cls Class of model based on BaseDataModel
@param dataID "dataID" of model based on BaseDataModel
@return sql string
*/
- (NSString *)remove:(Class _Nonnull)cls dataID:(NSInteger)dataID;

Parser(Model based on BaseDataModel encode and decode)

2.0~

-parserSQL:finish:

Model(基于 BaseDataModel) 存入,支持嵌入模型的属性,但嵌入的模型也要基于 BaseDataModel。(Model based on BaseDataModel encode by database, and embed model based on BaseDataModel also supported.)

参数:

model Model(基于 BaseDataModel) ,非必填 id
finish 解析完成回调,ParserSQLFinishBlock 实例,非必填 ParserSQLFinishBlock

返回值:

-parserModel:finish:

Model(基于 BaseDataModel) 取出,提供 model(基于 BaseDataModel) 的类。(Model based on BaseDataModel decode from database with class of a model based on BaseDataModel.)

参数:

cls Model(基于 BaseDataModel) 的类,必填 Class
finish 解析完成回调,ParserModelFinishBlock 实例,非必填 ParserModelFinishBlock

返回值:

-parserModel:dataID:finish:

Model(基于 BaseDataModel) 取出,提供 model(基于 BaseDataModel) 的类和 dataID。(Model based on BaseDataModel decode from database with class and dataID of a model based on BaseDataModel.)

参数:

cls Model(基于 BaseDataModel) 的类,必填 Class
dataID Model(基于 BaseDataModel) 的dataID,必填 NSInteger
finish 解析完成回调,ParserModelFinishBlock 实例,非必填 ParserModelFinishBlock

返回值:

-parserModel:dataName:finish:

Model(基于 BaseDataModel) 取出,提供 model(基于 BaseDataModel) 的类和 dataName。(Model based on BaseDataModel decode from database with class and dataName of a model based on BaseDataModel.)

参数:

cls Model(基于 BaseDataModel) 的类,必填 Class
dataName Model(基于 BaseDataModel) 的dataName,必填 NSString
finish 解析完成回调,ParserModelFinishBlock 实例,非必填 ParserModelFinishBlock

返回值:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//MARK: - Parser
typedef void (^_Nullable ParserSQLFinish)(NSString *_Nonnull sql, BOOL success);
typedef void (^_Nullable ParserModelFinish)(NSArray *_Nonnull model_array);
/**
Model(基于 BaseDataModel) 存入,支持嵌入模型的属性,但嵌入的模型也要基于 BaseDataModel。(Model based on BaseDataModel encode by database, and embed model based on BaseDataModel also supported.)

@param model Model based on BaseDataModel
@param finish 解析完成回调,ParserSQLFinishBlock 实例
*/
- (void)parserSQL:(id _Nullable)model finish:(ParserSQLFinish)finish;
/**
Model(基于 BaseDataModel) 取出,提供 model(基于 BaseDataModel) 的类。(Model based on BaseDataModel decode from database with class of a model based on BaseDataModel.)

@param cls Class of model based on BaseDataModel
@param finish 解析完成回调,ParserModelFinishBlock 实例
*/
- (void)parserModel:(Class _Nonnull)cls finish:(ParserModelFinish)finish;
/**
Model(基于 BaseDataModel) 取出,提供 model(基于 BaseDataModel) 的类和 dataID。(Model based on BaseDataModel decode from database with class and dataID of a model based on BaseDataModel.)

@param cls Class of model based on BaseDataModel
@param dataID "dataID" of model based on BaseDataModel
@param finish 解析完成回调,ParserModelFinishBlock 实例
*/
- (void)parserModel:(Class)cls dataID:(NSInteger)dataID finish:(ParserModelFinish)finish;
/**
Model(基于 BaseDataModel) 取出,提供 model(基于 BaseDataModel) 的类和 dataName。(Model based on BaseDataModel decode from database with class and dataName of a model based on BaseDataModel.)

@param cls Class of model based on BaseDataModel
@param dataName "dataName" of model based on BaseDataModel
@param finish 解析完成回调,ParserModelFinishBlock 实例
*/
- (void)parserModel:(Class)cls dataName:(NSString *)dataName finish:(ParserModelFinish)finish;

相关

更新内容

  1. 相关链接调整。
  2. 新增相关代码示例。