Latest 0.1.0
Homepage https://github.com/lywsbcn/Jsqlite
License MIT
Platforms ios 8.0
Dependencies YYModel
Authors

CI Status
Version
License
Platform

Example

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

Installation

Jsqlite is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'Jsqlite'

Use

JSQLconn

sqlite 连接管理

设置数据库名称,默认为 appSqlite.sqlite

数据库位置 沙盒/Documents/appSqlite.sqlite

[JSQLconn instance][email protected]"appSqlite.sqlite"

打开数据库
如果数据库存在就打开,如果不存在就创建一个再打开

BOOL success = [[JSQLconn instance] openDB];

关闭数据库

[[JSQLconn instance] closeDB];

执行 sql 语句

[[JSQLconn instance] execuSQL:(NSString *)SQL];

查询数据库中数据

-(NSArray *)querySQL:(NSString *)SQL WithClass:(Class)name;
-(NSArray *)querySQL:(NSString *)SQL

获取插入数据后的 id值(主键,自增)

[[JSQLconn instance] getID];

获取受影响的记录数
(增,改,删)

 [[JSQLconn instance] changes];

JSQLct

创建表格

根据 map 创建字段

范例1:

    @{
         @"id":JSQCT_PRIMARY,
         @"user_id":JSQCT_INTEGER,
         @"username":JSQCT_TEXT,
         @"token":JSQCT_TEXT,
         @"logintime":JSQCT_INTEGER
     }

范例2:

     @{
           @"id":@["INTEGER","PRIMARY KEY"],            
     };
[JSQLct instance].table(NSString *name).column(NSDictionary *data);

同时创建多张表

范例1:

    @{
         @"user":@{
             @"id":JSQCT_PRIMARY,
             @"user_id":JSQCT_INTEGER,
             @"username":JSQCT_TEXT,
             @"token":JSQCT_TEXT,
             @"logintime":JSQCT_INTEGER
         }
     }

范例2:

     @{
         @"user":@{
             @"id":@["INTEGER","PRIMARY KEY"],
            }
     };

[JSQLct instance].list(NSDictionary *data);

内部实现

for(NSString * tablename in data){
    wself.table(tablename).column([data objectForKey:tablename]);
}

查询列表,返回一个数组

NSArray * arr =[Jsqlite instance].table("user").select();

返回Class 数组

NSArray * arr =[Jsqlite instance].table("user").className(Class name).select();

条件查询

NSArray * arr =[Jsqlite instance].table("user").where("id=%ld",userid).select();

筛选的字段

NSArray * arr =[Jsqlite instance].table("user").where("id=%ld",userid).field("id,username,createtime").select();

排序

[Jsqlite instance].table("user").field("id,username,createtime").order("createtime desc").select();

分页

NSArray * arr =[Jsqlite instance].table("user").limit(10).select();

NSArray * arr =[Jsqlite instance].table("user").limit_two(0,10).select();

获取一条数据

NSDictionary * data = [Jsqlite instance].table("user").find();

添加一条数据 返回插入数据的id

NSInteget id = [Jsqlite instance].table("user").insert(id data);

一次性插入多条数据

NSInteget changes = [Jsqlite instance].table("user").insertAll(NSArray* data);

更新数据

NSInteget changes = [Jsqlite instance].table("user").update(NSDictionary* data);

删除记录

NSInteget changes = [Jsqlite instance].table("user").where("id>0").del();

数据数量

NSInteget count = [Jsqlite instance].table("user").count();

记录是否存在

BOOL exsits = [Jsqlite instance].table("user").where("id=%ld",id).exists();

Author

lywsbcn, [email protected]

License

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

Latest podspec

{
    "name": "Jsqlite",
    "version": "0.1.0",
    "summary": "Jsqlite. u6570u636eu5e93",
    "description": "TODO: Add long description of the pod here.",
    "homepage": "https://github.com/lywsbcn/Jsqlite",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "lywsbcn": "[email protected]"
    },
    "source": {
        "git": "https://github.com/lywsbcn/Jsqlite.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Jsqlite/Classes/**/*",
    "libraries": "sqlite3",
    "dependencies": {
        "YYModel": []
    }
}

Pin It on Pinterest

Share This