ICRDataBaseController.h 1.92 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 50 51 52 53 54 55 56
//
//  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;

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

@end