ICRDataBaseController.h 2.09 KB
Newer Older
mei's avatar
mei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
//
//  ICRDataBaseController.h
//  XFFruit
//
//  Created by Xummer on 4/5/15.
//  Copyright (c) 2015 Xummer. All rights reserved.
//

#import "IBTObject.h"
#import "FMDB.h"

typedef void (^ICRDatabaseUpdateBlock)(FMDatabase *db);
typedef FMResultSet *(^ICRDatabaseFetchBlock)(FMDatabase *db);
typedef void(^ICRDatabaseFetchResultsBlock)(NSArray *fetchedObjects);

@protocol IBTDatabaseObject;
@interface ICRDataBaseController : IBTObject

+ (instancetype)sharedController;

+ (NSString *)GetDataBasePath;
+ (void)CleanUpDBPath;

#pragma mark - Storage
- (void)storageEntities:(NSArray *)arrObjects
            objectClass:(Class<IBTDatabaseObject>)DBObjClass
            deleteLocal:(BOOL)bDeleteLocal
             handleData:(void (^)(id <IBTDatabaseObject>))handleDataBlock
               complete:(void (^)(void))complete
                   fail:(void (^)(NSError *))fail;

- (void)storageEntities:(NSArray *)arrObjects
            objectClass:(Class<IBTDatabaseObject>)DBObjClass
              updateNil:(BOOL)bUpdateNil
            deleteLocal:(BOOL)bDeleteLocal
             handleData:(void (^)(id <IBTDatabaseObject>))handleDataBlock
               complete:(void (^)(void))complete
                   fail:(void (^)(NSError *))fail;

- (void)storageEntity:(NSDictionary *)dictObject
          objectClass:(Class<IBTDatabaseObject>)DBObjClass
           handleData:(void (^)(id <IBTDatabaseObject>))handleDataBlock
             complete:(void (^)(void))complete
                 fail:(void (^)(NSError *))fail;

- (void)storageDBObject:(id<IBTDatabaseObject>)dbObj
             handleData:(void (^)(id <IBTDatabaseObject>))handleDataBlock
               complete:(void (^)(void))complete
                   fail:(void (^)(NSError *))fail;
50 51 52 53
/**
 *  兼容性校验,对于后来增加的字段进行校验,没有的话进行对应操作。应该在APP初始化的时候就调用
 */
- (void)compatibilityCheck;
mei's avatar
mei committed
54 55 56 57 58 59 60

#pragma mark - Query
- (void)runFetchForClass:(Class<IBTDatabaseObject>)dbObjClass
              fetchBlock:(ICRDatabaseFetchBlock)fetchBlock
       fetchResultsBlock:(ICRDatabaseFetchResultsBlock)fetchResultBlock;

@end