Latest 0.3.1
Homepage https://github.com/lazyaudio/LRTSSQliteManager
License MIT
Platforms ios 8.0
Dependencies WCDB
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • WCDB 基础之上进行再次封装,需要瞒住版本:iOS 7.0 及其之后版本
  • Xcode 8.0 及其之后版本
  • Model 和 调用的类需要 Objective-C++

Installation

LRTSSQliteManager 是基于第三方开源库 WCDB 之上来进行解决在数据操作过程中使用大量胶水代码和防止反注入问题,在使用时需要在项目中加入 WCDB 第三方开源库代码。

  • 使用 CocoaPods 来进行安装:
    • (1)安装[CocoaPods](https://guides.cocoapods.org/using/getting-started.html)
    • (2)通过 `pod repo update` 来更新 `LRTSSQliteManager` 版本
    • (3)在项目的 `podfile` 对应的 `target` 中添加 `pod ‘LRTSSQliteManager’`,并且执行 `pod install –verbose`
    • (4)在项目中会会生成 `.xcworkspace` 的运行工程
    • (5)在需要使用的项目中引入 `#import ` 来进行封装对数据库多种操作
    • (6)在使用 `LRTSOperation` 过程中会引入 `C++` 文件,项目的后缀由 `.m` 变为 `.mm`

基础接口使用说明

在基础接口中包括常用的数据操作的增、删、改和查。详细的接口内容可以参考:LRTSOperation.h

Model 实现数据绑定

在 Model 数据绑定需要三个文件:BookDetail.hBookDetail.mBookDetail+WCTTableCoding

  • BookDetail.h数据解析
#import <Foundation/Foundation.h>
#import "LRTSDBModel.h"

//Model 继承与 LRTSDBModel 
@interface BookDetail : LRTSDBModel

@property(assign, nonatomic) NSInteger bookID;
@property(strong, nonatomic) NSString *bookName;
@property(strong, nonatomic) NSDate *upLoad;
@property(copy, nonatomic) NSString *pubilsher;

//WCDB_PROPERTY(BookDetail);

@end
  • BookDetail.m属性综合
#import "BookDetail.h"
#import <WCDB/WCDB.h>

@implementation BookDetail

//数据库名字的 WING 绑定
WCDB_IMPLEMENTATION(BookDetail)

//Model 类中属性 WING 到表中列名
WCDB_SYNTHESIZE(BookDetail, bookID)
WCDB_SYNTHESIZE(BookDetail, bookName)
WCDB_SYNTHESIZE(BookDetail, upLoad)
WCDB_SYNTHESIZE(BookDetail, pubilsher)

//Model 类中属性 WING 到数据表中重命名 
WCDB_SYNTHESIZE_COLUMN(BookDetail, pubilsher, @"出版")

//设置 bookID 为 UNIQUE 
WCDB_UNIQUE(BookDetail, bookID)

@end
  • BookDetail+WCTTableCoding属性声明
#import "BookDetail.h"
#import <WCDB/WCDB.h>

@interface BookDetail (WCTTableCoding)<WCTTableCoding>

//属性声明的绑定
WCDB_PROPERTY(bookID)
WCDB_PROPERTY(bookName)
WCDB_PROPERTY(upLoad)
WCDB_PROPERTY(pubilsher)

@end

LRTSOperation 接口使用

  • 数据表创建代码实例
//定义创建数据库的名字:lazyAudioPlayer.db
#define LAZY_AUDIO_PLAYER @"lazyAudioPlayer"

@interface LRTSDBOperation ()

@property (nonatomic, strong) LRTSOperation *operation;

@property (nonatomic, strong) BookDetail *bookDetail;

@end

//Lazy Loading Operation 的操作
//创建数据库 lazyAudioPlayer.db,默认创建地址:Documents/
- (LRTSOperation *)operation {
    if (!_operation) {
        _operation = [[LRTSOperation alloc] initWCDBWithName:LAZY_AUDIO_PLAYER];
    }
    return _operation;
}

//Lazy Loading BookDetail 书籍详细 Model
- (BookDetail *)bookDetail {
    if (!_bookDetail) {
        _bookDetail = [[BookDetail alloc] init];
    }
    return _bookDetail;
}

//创建 BookDetail ROM 绑定的 Table 表,默认表明是:BookDetail
[self.operation createTableWithDBModel:self.bookDetail];
  • 数据库添加或者是更新操作代码实例
// model 是 BookDetail 实例化的对象
[self.operation insertOrReplaceObject:model into:NSStringFromClass(BookDetail.class)];
  • 数据库删除操作代码实例
// BookDetail.bookID 是删除的条件
[self.operation deleteObjectsFromTable:NSStringFromClass(BookDetail.class) where:BookDetail.bookID == bookId];
  • 数据库更新操作代码实例
//BookDetail.bookName 是要更新的字段
//model 是要更新内容的实例化变量
//BookDetail.bookID 是更新在具体的字段
[self.operation updateRowsInTable:NSStringFromClass(BookDetail.class) onValue:BookDetail.bookName withObject:model where:BookDetail.bookID == bookId];
  • 数据库查找操作代码实例
//BookDetail.bookID 需要查找的条件
[self.operation getObjectsForTable:NSStringFromClass(BookDetail.class) where:BookDetail.bookID == bookId];
  • 多个数据表数据查询
//{BookDetail.bookName.inTable(nameBookDetail), Book.autor.inTable(nameBook)} 获取数据的列数
//@[nameBook, nameBookDetail] 获取内容来自的表格
//Book.bookID 来自查找的条件
NSString *nameBookDetail = NSStringFromClass(BookDetail.class);
NSString *nameBook = NSStringFromClass(Book.class);
[self.operation selectRowsOnResults:{BookDetail.bookName.inTable(nameBookDetail), Book.autor.inTable(nameBook)} fromTables:@[nameBook, nameBookDetail] where:Book.bookID == 1000];

Author

boilwater, [email protected]

License

LRTSSQliteManager is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "LRTSSQliteManager",
    "version": "0.3.1",
    "summary": "LRTSSQliteManager u5b9eu73b0u5bf9u516cu53f8u7684u6570u636eu5e93u64cdu4f5cu7684 SQL u7684u589eu5220u6539u67e5u7684u64cdu4f5cu8bedu53e5u66ffu6362u7684u4e00u79cdu89e3u51b3u65b9u6848",
    "description": "u4f9du636eu5faeu4fe1u7684 WCDB u7684u5f00u6e90u51fdu6570u5e93u6765u5b9eu73b0u5bf9u4e8eu6570u636eu5e93 SQL u4e2du589eu5220u6539u548cu591au79cdu60c5u51b5u4e0bu7684u67e5u627eu60c5u51b5uff0cu6765u89e3u51b3 u201cu80f6u6c34u4ee3u7801u95eeu9898u201d",
    "homepage": "https://github.com/lazyaudio/LRTSSQliteManager",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "boilwater": "[email protected]"
    },
    "source": {
        "git": "https://github.com/lazyaudio/LRTSSQliteManager.git",
        "tag": "0.3.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "LRTSSQliteManager/Classes/**/*",
    "dependencies": {
        "WCDB": []
    }
}

Pin It on Pinterest

Share This