Giter Club home page Giter Club logo

gxdatabaseutils's Introduction

GXDatabaseUtils

  • simplify sqlite database CRUD operation.
  • Support ARC.
  • Support ios8 and before.

Screen shot

How To Get Started

  • Copy file under src and catagory directory to your project
  • Download fmdb relevant file
  • Add libsqlite3.dylib to project

Support data types

  • BOOL
  • unsigned int
  • NSInteger
  • long long
  • CGFloat
  • double
  • NSString
  • BOOL for ios8
  • Enum for ios8

Support iOS version

iOS5 later

Relationship class Member and column name

RULE: column name is member name of class.

For example:

// class
@interface GXBaseMessage : NSObject {
    
    NSString *address;
}

@property (nonatomic, assign) NSInteger count;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSMutableArray *datas;
@end
member name column name
address address
count _count
name _name
datas -

Dependencies

  • fmdb needed
  • NSObject subclass

Architecture

  • <catagory>
  • NSObject+serializable
  • <src>
  • GXDatabaseManager
  • GXSQLStatementManager
  • GXCache

Usage

CRUD operation

  • C-Create
  • R-Retrieve
  • U-Update
  • D-Delete

Create

NSString *dbPath = [NSHomeDirectory() stringByAppendingPathComponent:@"testDB.sqlite"];
BOOL res = [GXDatabaseManager databaseWithPath:dbPath];
res = [GXDatabaseManager createTable:@"t_message" withClass:[GXMessage class] withPrimaryKey:@"_msgId"];

Retrieve

NSString *dbPath = [[NSBundle mainBundle] pathForResource:@"db" ofType:@"sqlite"];
BOOL res = [GXDatabaseManager databaseWithPath:dbPath];
if (!res) {
    NSLog(@"ERROR...");
}
    
NSString *w1 = kWhereString(@"_sessionUserid", @"=");
NSString *w2 = kWhereString(@"_msgId", @"=");
NSString *w = kWhereCombination(w1, @"AND", w2);
    
[GXDatabaseManager selectObjects:[GXMessageDBEntity class]
                       fromTable:@"t_message_chat"
                           where:w
                      withParams:@[@"1525851662", @"615734ef-2db1-427a-9505-b49ec6a8628c"]
                         orderBy:@"_msgTime"
                    withSortType:@"DESC"
                       withRange:NSMakeRange(0, 5)];

Update

// replace into
NSString *dbPath = [NSHomeDirectory() stringByAppendingPathComponent:@"testDB.sqlite"];
BOOL res = [GXDatabaseManager databaseWithPath:dbPath];

// create table
res = [GXDatabaseManager createTable:@"t_message" withClass:[GXMessage class] withPrimaryKey:@"_msgId"];
    
[GXDatabaseManager replaceInto:@"t_message" withObject:msg];
// update
NSString *dbPath = [NSHomeDirectory() stringByAppendingPathComponent:@"testDB.sqlite"];
BOOL res = [GXDatabaseManager databaseWithPath:dbPath];
    
if (!res) NSLog(@"ERROR");
    
    
NSString *w = kWhereString(@"_msgId", @"=");
[GXDatabaseManager updateTable:@"t_message"
                           set:@[@"_fontName"]
                         where:w
                    withParams:@[@"黑体", @"1ccaf308-8bb0-1e44-2f0b-98f308d03d57"]];

Delete

NSString *dbPath = [[NSBundle mainBundle] pathForResource:@"db" ofType:@"sqlite"];
BOOL res = [GXDatabaseManager databaseWithPath:dbPath];
if (!res) NSLog(@"ERROR...");
    
[GXDatabaseManager deleteTable:@"t_message_chat" where:@"_msgId=?" withParams:@[@"1ccaf308-8bb0-1e44-2f0b-98f308d03d57"]];

License

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

gxdatabaseutils's People

Contributors

gerry1218 avatar

Watchers

James Cloos avatar ekingo Hu 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.