All Projects → pozi119 → VVSequelize

pozi119 / VVSequelize

Licence: MIT License
数据库模型映射,自动建表, 自动更新表,数据增删改查, FTS全文搜索, 支持自定义fts3,4,5分词器,可拼音分词. sql,fmdb,wcdb,sqlite3,orm,fts,fts3,fts4,fts5

Programming Languages

objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to VVSequelize

Swift-FFDB
a Object/Relational Mapping (ORM) support to iOS and MacOS .Since SwiftFFDB is build on top of FMDB.
Stars: ✭ 22 (+37.5%)
Mutual labels:  fmdb, sqlite3
csv-to-sqlite
A desktop app to convert CSV files to SQLite databases!
Stars: ✭ 68 (+325%)
Mutual labels:  sqlite, sqlite3
LoginToASqlite3DatabaseWithoutCredentialsWithAdminer
✔️ An Adminer plugin to use SQLite databases without credentials (no username and no password)
Stars: ✭ 30 (+87.5%)
Mutual labels:  sqlite, sqlite3
React Native Sqlite 2
SQLite3 Native Plugin for React Native for iOS, Android, Windows and macOS.
Stars: ✭ 217 (+1256.25%)
Mutual labels:  sqlite, sqlite3
PokeChat
UNIX compatible, Discord and Telegram inspired, Pokémon-themed instant messaging service.
Stars: ✭ 11 (-31.25%)
Mutual labels:  sqlite, sqlite3
Sqleet
SQLite3 encryption that sucks less
Stars: ✭ 244 (+1425%)
Mutual labels:  sqlite, sqlite3
nim-gatabase
Connection-Pooling Compile-Time ORM for Nim
Stars: ✭ 103 (+543.75%)
Mutual labels:  sqlite, sqlite3
Sqlittle
Pure Go SQLite file reader
Stars: ✭ 171 (+968.75%)
Mutual labels:  sqlite, sqlite3
selekt
A Kotlin and Android wrapper over SQLCipher, providing 256-bit AES encryption of database files.
Stars: ✭ 26 (+62.5%)
Mutual labels:  sqlite, sqlite3
python-sqlite3-backup
Sqlite3 online API CPython implementation module
Stars: ✭ 44 (+175%)
Mutual labels:  sqlite, sqlite3
Better Sqlite3
The fastest and simplest library for SQLite3 in Node.js.
Stars: ✭ 2,778 (+17262.5%)
Mutual labels:  sqlite, sqlite3
lighthouse
Easy clojure relational database queries, migrations and connection pooling
Stars: ✭ 19 (+18.75%)
Mutual labels:  sqlite, sqlite3
Pydbgen
Random dataframe and database table generator
Stars: ✭ 191 (+1093.75%)
Mutual labels:  sqlite, sqlite3
Mikro Orm
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.
Stars: ✭ 3,874 (+24112.5%)
Mutual labels:  sqlite, sqlite3
Choochoo
Training Diary
Stars: ✭ 186 (+1062.5%)
Mutual labels:  sqlite, sqlite3
go-sqlite
Low-level Go interface to SQLite 3
Stars: ✭ 268 (+1575%)
Mutual labels:  sqlite, sqlite3
Sqlite Parquet Vtable
A SQLite vtable extension to read Parquet files
Stars: ✭ 167 (+943.75%)
Mutual labels:  sqlite, sqlite3
Rom Sql
SQL support for rom-rb
Stars: ✭ 169 (+956.25%)
Mutual labels:  sqlite, sqlite3
react-native-quick-sqlite
Fast SQLite for react-native.
Stars: ✭ 239 (+1393.75%)
Mutual labels:  sqlite, sqlite3
sqlite zstd vfs
SQLite3 extension for read/write storage compression with Zstandard
Stars: ✭ 42 (+162.5%)
Mutual labels:  sqlite, sqlite3

VVSequelize

Version License Platform

改动(0.4.7)

  1. 移除accessible. 不建议访问appgroup中的数据库, 所以去掉此功能.
  2. 移除cache. 因为sqlite3_update_hook()不能完全hook所有delete, drop操作, cache将不能被有效更新,会导致查询到错误数据, 所以去掉此功能, 由用户自行管理缓存.

功能

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

结构

安装

pod 'VVSequelize', '~> 0.4.7'

使用测试版本:

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

注意

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

用法

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

打开/创建数据库文件

    self.vvdb = [[VVDatabase alloc] initWithPath:dbPath];

定义ORM配置

  1. 手动创建VVOrmConfig.
  2. 普通表适配协议VVOrmable, fts表适配协议VVFtsable

注意: 已移除fts3/4的支持,仅使用fts5

定义ORM模型

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

示例如下:

item.orm = [VVOrm ormWithClass:VVMessage.class name:item.tableName database:item.db];
        
item.ftsOrm = [VVOrm ormWithFtsClass:VVMessage.class name:item.tableName database:item.ftsDb];

增删改查

使用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 limit:10 offset:0];
    
...

生成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 new];
    select.table(@"mobiles");
    select.where(@"relative".lt(@(0.3))
                 .and(@"mobile".gte(@(1600000000)))
                 .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(10);
    NSLog(@"%@", select.sql);
    select.distinct(YES);
    NSLog(@"%@", select.sql);
}

原生语句查询

- (NSArray<NSDictionary *> *)query:(NSString *)sql;

- (NSArray *)query:(NSString *)sql clazz:(Class)clazz;

加密数据数据转换(sqlcipher 3.x->4.x)

    VVDatabase *database = [VVDatabase databaseWithPath:path flags:0 encrypt:@"XXXXX"];
    database.cipherOptions = @[
        @"pragma cipher_page_size = 4096;", ///<3.x的cipher_page_size,默认为1024
        @"pragma kdf_iter = 64000;",
        @"pragma cipher_hmac_algorithm = HMAC_SHA1;",
        @"pragma cipher_kdf_algorithm = PBKDF2_HMAC_SHA1;"
    ];

Author

Valo Lee, [email protected]

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].