美文网首页
告别sqlite的复杂语法

告别sqlite的复杂语法

作者: 师傅我坚持不住了 | 来源:发表于2018-08-25 02:03 被阅读5次

    使用方便,不必再去写繁琐的sqlite语法.

    使用

    1. 引入sqlite3 API.
    2. pod 'SLCSqlite'
    3. 创建sqlite文件.
    SLCSqlite *sqlite = [SLCSqlite sqliteWithFilePath:[NSString stringWithFormat:@"%@/%@",SLCDoucumentPath.library,@"my.sqlite"]];
    
    1. 创建表.
      通过键值的方式,创建字段和对应类型.
    [sqlite createTable:@"t_table"
    keyValues:@{
    @"id":@(SLCSqliteValueTypeInteger | SLCSqliteValueTypeNotNull | SLCSqliteValueTypePrimaryKey | SLCSqliteValueTypeAutoincrement),
    @"name":@(SLCSqliteValueTypeText),
    @"age":@(SLCSqliteValueTypeInteger)
    }];
    
    [sqlite insert:@"t_table"
    keyValues:@{
    @"name":@"Tom",
    @"age":@(20)
    }];
    
    [sqlite deleted:@"t_table"
    conditions:@{
    @"name":SLCConditionEqual(@"Tom")
    }];
    
    [sqlite update:@"t_table"
    keyValues:@{
    @"name":@"Lisa",
    @"age":@(18)
    } conditions:@{
    @"id":SLCConditionEqual(@15),
    @"name":SLCConditionEqual(@"Tom")
    }];
    
    [sqlite query:@"t_table"
    type:SLCQueryTypeAll
    conditions:@{
    @"id":SLCConditionOrderDesc()
    } queryBlock:^(SLCSqliteValue *sqliteValue) {
    
    int ID = [sqliteValue intForIndex:0];
    NSString *name = [sqliteValue stringForIndex:1];
    int age = [sqliteValue intForIndex:2];
    NSLog(@"%d,%@,%d",ID,name,age);
    }];
    

    如有bug或问题,请私信.github地址.

    相关文章

      网友评论

          本文标题:告别sqlite的复杂语法

          本文链接:https://www.haomeiwen.com/subject/wbdwiftx.html