Latest 0.3.0-beta2
Homepage https://github.com/pozi119/VVSequelize
License MIT
Platforms ios 8.0
Authors

Version
License
Platform

功能

  • [x] 根据Class生成数据表
  • [x] 增删改查,insert,update,upsert,delele,drop…
  • [x] Where语句生成,可满足大部分常规场景
  • [x] 数据库加解密(SQLCipher)
  • [x] 原生SQL语句支持
  • [x] 常规查询支持,max,min,sum,count…
  • [x] 主键支持(可自动主键),唯一性约束支持.
  • [x] Transaction支持
  • [x] Object直接处理
  • [x] 数据存储,OC类型支持: NSData, NSURL, NSSelector, NSValue, NSDate, NSArray, NSDictionary, NSSet,…
  • [x] 数据存储,C类型支持: char *, struct, union
  • [x] 子对象存储为Json字符串
  • [x] OrmModel查询缓存
  • [x] FTS全文搜索

改动(0.3.0-beta2)

  1. 可创建内存数据库,未测试
  2. 添加通用的版本升级辅助类VVUpgrader

安装

使用测试版本:

    pod 'VVSequelize', :git => 'https://github.com/pozi119/VVSequelize.git'

使用稳定版本:

    pod 'VVSequelize', '0.2.1'

注意

  1. 子对象会保存成为Json字符串,子对象内的NSData也会保存为16进制字符串.
  2. 含有子对象时,请确保不会循环引用,否则Dictionary/Object互转会死循环,请将相应的循环引用加入互转黑名单.
  3. VVKeyValue仅用于本工具,不适用常规的Json转对象.

用法

此处主要列出一些基本用法,详细用法请阅读代码注释.

全局配置

sqlite3封装类请参考VVSequelize_TestsVVTestDBClass的实现方式.

    // 必须设置sqlite3封装类
    [VVSequelize setDbClass:VVTestDBClass.class];

    [VVSequelize setTrace:^(NSString *sql, NSArray *values, id results, NSError *error) { 
        //加入对每个sql执行情况的跟踪
    }];

打开/创建数据库文件

    self.vvdb = [[VVDataBase alloc] initWithDBName:@"mobiles.sqlite"];

定义ORM配置

使用VVOrmConfig统一表配置,方便复用,支持链式赋值.

    VVOrmConfig *config = [[VVOrmConfig configWithClass:VVTestMobile.class] primaryKey:@"mobile"];

定义ORM模型

可自定义表名和存放的数据库文件.
生成的模型将不在保存在ModelPool中,防止表过多导致内存占用大,需要请自行实现.

示例如下:

    self.mobileModel = [VVOrm ormModelWithConfig:config tableName:@"mobiles" dataBase:self.vvdb];

增删改查

使用ORM模型进行增删改查等操作.

示例如下:

NSInteger count = [self.mobileModel count:nil];
BOOL ret = [self.mobileModel increase:nil field:@"times" value:-1];
NSArray *array = [self.mobileModel findAll:nil orderBy:nil range:NSMakeRange(0, 10)];
...

生成SQL子句

现在仅支持非套嵌的字典或字典数组,转换方式如下:

//where/having :
{field1:val1,field2:val2} --> field1 = "val1" AND field2 = "val2"
[{field1:val1,field2:val2},{field3:val3}] --> (field1 = "val1" AND field2 = "val2") OR (field3 = "val3")
//group by:
[filed1,field2] --> "field1","field2"
//order by
[filed1,field2] --> "field1","field2" ASC
[filed1,field2].desc --> "field1","field2" DESC

示例:

- (void)testClause{
    VVSelect *select = [[VVSelect prepare] table:@"mobiles"];
    [select where:[[[@"relative" lt:@(0.3)] and:[@"mobile" gte:@(16000000000)]] and: [@"times" gte:@(0)]]];
    NSLog(@"%@", select.sql);
    [select where:@{@"city":@"西安", @"relative":@(0.3)}];
    NSLog(@"%@", select.sql);
    [select where:@[@{@"city":@"西安", @"relative":@(0.3)},@{@"relative":@(0.7)}]];
    NSLog(@"%@", select.sql);
    [select where:[@"relative" lt:@(0.3)]];
    NSLog(@"%@", select.sql);
    [select where:@"     where relative < 0.3"];
    NSLog(@"%@", select.sql);
    [select groupBy:@"city"];
    NSLog(@"%@", select.sql);
    [select groupBy:@[@"city",@"carrier"]];
    NSLog(@"%@", select.sql);
    [select groupBy:@" group by city carrier"];
    NSLog(@"%@", select.sql);
    [select having:[@"relative" lt:@(0.2)]];
    NSLog(@"%@", select.sql);
    [select groupBy:nil];
    NSLog(@"%@", select.sql);
    [select orderBy:@[@"city",@"carrier"]];
    NSLog(@"%@", select.sql);
    [select orderBy:@" order by relative"];
    NSLog(@"%@", select.sql);
    [select limit:NSMakeRange(0, 10)];
    NSLog(@"%@", select.sql);
    [select distinct:YES];
    NSLog(@"%@", select.sql);
}

Author

Valo Lee, [email protected]

License

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

Latest podspec

{
    "name": "VVSequelize",
    "version": "0.3.0-beta2",
    "summary": "u57fau4e8eFMDBu7684ORMu6a21u578bu5c01u88c5.",
    "description": "u57fau4e8eFMDBu7684ORMu6a21u578bu5c01u88c5.",
    "homepage": "https://github.com/pozi119/VVSequelize",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Valo Lee": "[email protected]"
    },
    "source": {
        "git": "https://github.com/pozi119/VVSequelize.git",
        "tag": "0.3.0-beta2"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "VVSequelize/**/*"
}

Pin It on Pinterest

Share This