Giter VIP home page Giter VIP logo

sqlight's Introduction

SQLight

SQLite封装,让SQLite操作简单的就像NSUserDefaults一样.

使用方法

import SQLight的头文件 Sqlite.h

#import "Sqlite.h"

SQLight是对iOS SDK中提供的SQLite组件的一个封装。通过构造方法可以活的一个数据库或者某数据表的操作句柄(一个适配器实例),通过句柄可以对数据库进行各种操作。并以SqlightResult对象的方式返回结果,其中包括 code(sqlite默认的状态码 101表示正确完成)、msg(错误信息)和data(查询时的结果集)。

活的数据表句柄

SqlightAdapter *sqlight = [SqlightAdapter database:dbName AndTable:tbName];
if (nil == sqlight) { // 数据表不存在,初始化失败。创建表。
    sqlight = [SqlightAdapter database:dbName];
    [sqlight createTable:tbName Info:[NSMutableArray arrayWithObjects:
                                      @"id INTEGER PRIMARY KEY ASC",
                                      @"type INTEGER",
                                      @"style INTEGER",
                                      @"content",
                                      @"created INTEGER",
                                      nil]];
  
    sqlight.tableName = tbName;
}

插入数据

SqlightAdapter *sqlightB = [SqlightAdapter database:dbName AndTable:tbName];
SqlightResult *result = [sqlightB insertData:[NSDictionary dictionaryWithObjectsAndKeys:
                                             @"1",                  @"type",
                                             @"2",                  @"style",
                                             @"This is a Demo.",    @"content",
                                             nil]];

查询数据

SqlightAdapter *sqlightC = [SqlightAdapter database:dbName AndTable:tbName];
SqlightResult *queryResult = [sqlightC selectFields:[NSArray arrayWithObjects:@"id", @"type", @"style", @"content", nil]
                                       ByCondition:@""
                                              Bind:nil];

更新数据

SqlightAdapter *sqlightD = [SqlightAdapter database:dbName AndTable:tbName];
SqlightResult *updateResult = [sqlightD updateData:[NSDictionary dictionaryWithObjectsAndKeys:
                                                   @"1",                  @"type",
                                                   @"20",                 @"style",
                                                   @"This is a Demo.",    @"content",
                                                   nil]
                                      ByCondition:@"type=?"
                                             Bind:[NSArray arrayWithObjects:@"1", nil]];

除此之外,开发者还可以通过 excuteSQL: bind: 方法直接执行SQL语句,获取SqlightResult。

具体使用方法可参考工程中的Demo

sqlight's People

Contributors

gaosboy avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.