Git Product home page Git Product logo

dbassistant's Introduction

DBAssistant

DBAssistant base on FMDB and it provide a simple way to access sqlite database.

Getting started

  • add pod ‘DBAssistant’ to your Podfile
  • run pod install
  • import "NSObject+DB.h"

Example

create a file user.h

@interface User : NSObject
@property (strong, nonatomic) NSString *name;
@property (assign, nonatomic) CGFloat height;
@property (assign, nonatomic) NSInteger num;
@end

use the User model where you need

//create a new model
User *user = [[User alloc]init];
user.name = @"mason";
user.height = 180.23;
user.num = 123456;
[user saveModel]; 

NSLog(@"users count: %ld",User.allModels.count);

//find model
user = [User firstModelWhere:@{DBRowId: @(1)}];
NSLog(@"name %@,num: %ld,height: %lf",user.name,user.num,user.height);


//update model
[user updateModel:@{@"name": @"Dear"}];


user = [User firstModelWhere:@{DBRowId: @(1)}];
NSLog(@"name %@,num: %ld,height: %lf",user.name,user.num,user.height);

//delete model
[user deleteModel];
NSLog(@"users count: %ld",User.allModels.count);

More Interfaces

Configs
//dbPath
+(NSString*)dbPath;

//tableName,default is the current class
+(NSString*)tableName;

//primarykeys,default is DBRowID
+(NSArray*)primaryKeys;

//only properties to map table columns
+(NSArray *)onlyPropertiesToMapColumns;

//except properties to map table columns
+(NSArray *)exceptPropertiesToMapColumns;

//property to  column Mappings
+(NSDictionary *)propertyToColumnMappings;

//properties default values
+(NSDictionary *)defaultValues;

//properties value check values
+(NSDictionary *)checkValues;

//properties value length
+(NSDictionary *)lengthValues;

//properties value those should be unique
+(NSArray *)uniqueValues;

//properties value those should be not null
+(NSArray *)notNullValues;

+(NSString *)dateFormatterString;

+(NSString *)imagePathForImage:(NSString *)imgName ;

+(NSString *)dataPathForData:(NSString *)dataName;

//default is YES
+(BOOL)shouldMapAllParentPropertiesToTable;

//default is YES
+(BOOL)shouldMapAllSelfPropertiesToTable;

Create/Drop table
+(BOOL)createTable;

+(BOOL)dropTable;
Insert
+(BOOL)insertModel:(NSObject *)model;

+(BOOL)insertModelIfNotExists:(NSObject *)model;

-(BOOL)saveModel;
Update
+(BOOL)updateModelsWithModel:(NSObject *)model where:(NSObject *)where;

+(BOOL)updateModelsWithDictionary:(NSDictionary *)dic where:(NSObject *)where;

-(BOOL)updateModel:(id)value;
Find
+(BOOL)modelExists:(NSObject *)model;

+(NSArray *)allModels;

+(NSArray *)findModelsBySQL:(NSString *)sql;

+(NSArray *)findModelsWhere:(NSObject *)where;

+(NSArray *)findModelsWhere:(NSObject *)where orderBy:(NSString *)orderBy;

+(NSArray )findModelsWhere:(NSObject *)where groupBy:(NSString *)groupBy orderBy:(NSString)orderBy limit:(int)limit offset:(int)offset;

+(id)firstModelWhere:(NSObject *)where;

+(id)firstModelWhere:(NSObject )where orderBy:(NSString)orderBy ;

+(id)lastModel;

+(NSInteger)rowCountWhere:(NSObject *)where;
Delete
+(BOOL)deleteModel:(NSObject *)model;

+(BOOL)deleteModelsWhere:(NSObject *)where;

-(BOOL)deleteModel;
Transaction
+(void)beginTransaction;

+(void)commit;

+(void)rollback;

dbassistant's People

Contributors

iitvip avatar masong2012 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dbassistant's Issues

小建议

东西写的不错,但是下载之后不能直接跑起来,会影响别人给你加❤

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.