Giter VIP home page Giter VIP logo

sqlite_study's Introduction

###基于SQLite3轻量级封装,一行代码实现增删改查

// 打开数据库
[[GKDatabaseManager sharedManager]openDatabase]

// 创建表格
// 默认表为为类名,主键为t_default_id
[[GKDatabaseManager sharedManager] creatTableWithClassName:[Person class]];

// 插入数据
Person * p = [[Person alloc]init];
p.name =@"花菜ChrisCai";
p.age = 100;
[[GKDatabaseManager sharedManager] insertDataFromObject:p]

// 查询指定表内数据
NSArray * persons = [[GKDatabaseManager sharedManager] selecteDataWithClass:[Person class]];

// 模糊查找

// 枚举类型含义
typedef NS_ENUM(NSInteger ,GKDatabaseSelectLocation){
    /// 以某个字符串开头
    GKDatabaseSelectStartWithString = 0,
    /// 包含有某个字符串
    GKDatabaseSelectRangOfString,
    /// 以某个字符串结尾
    GKDatabaseSelectEndWithString
};
// 查询Person表格中所有年龄包含8的
NSArray * resultArr = [[GKDatabaseManager sharedManager] selectObject:[Person class] propertyName:@"age" type:GKDatabaseSelectRangOfString content:@"8"];

// 更新数据
// 将Student表中所有age = 100对应的记录name都改为Chris
[[GKDatabaseManager sharedManager] updateObject:[Student class] oldValues:@[@"age = 100"] conditionType:QueryTypeAND  newValues:@[@"name = Chris"]]

// 指定删除
// 删除Person表中所有age>50的记录
[[GKDatabaseManager sharedManager] deleteObject:[Person class] withString:@"age > 50"]

###新增方法

/**
 *  从表格中移除完全匹配对象属性的行
 *
 *  @param object 模型对象
 *
 *  @return 删除结果
 */
- (BOOL)deleteObject:(id)object; 
// 执行指自定义的sql语句,并返回结果
- (BOOL)executeSqlString:(NSString *)sqlString;

更多使用详情,请看Demo~ 原理篇请看这里简书地址

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.