IBTModel.h 1.71 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 57 58 59 60 61 62
//
//  IBTBaseEntity.h
//
//
//  Created by Xummer on 15/4/7.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "IBTObject.h"

@class FMResultSet;
@protocol IBTDatabaseObject <NSObject>

@property (strong, nonatomic) NSMutableArray *arrSubModels;

+ (id)DBObject;

+ (id)objectFromFetchResult:(FMResultSet *)result;
- (void)updateFromFetchResult:(FMResultSet *)result;

// Fuctions
- (NSDictionary *)dictForCommit;
- (NSDictionary *)dictForLocalSave;
- (void)praseFromJsonDict:(NSDictionary *)dict;
- (void)praseFromLocalDict:(NSDictionary *)dict;
- (void)praseFromJsonDict:(NSDictionary *)dict isNilLeague:(BOOL)bIsNilLeague;

// SQLite
+ (NSString *)TableName;
+ (NSString *)PrimaryKey;
+ (NSArray *)PrimaryKeys;

- (NSString *)SQLForInsertOrUpdate:(NSArray * __autoreleasing *)pValues;
+ (NSString *)SQLForCreateTable;

+ (NSString *)SQLForUpdateKeyValueDict:(NSDictionary *)kvDict
                          WhereInfoStr:(NSString *)nsWhereInfoStr;
+ (NSString *)SQLForUpdateKeyValueDict:(NSDictionary *)kvDict
                             WhereInfo:(NSDictionary *)dictWhere;

- (void)saveToDBWithHandleData:(void (^)(id <IBTDatabaseObject>))handleDataBlock
                      complete:(void (^)(void))complete
                          fail:(void (^)(NSError *))fail;

@end

@interface IBTModel : IBTObject <IBTDatabaseObject>

// 需要替换的 keys map, @"|property key|" : @"|json key|",  如: @{ @"customID" : @"id" }
+ (NSDictionary *)specialKeysAndReplaceKeys;

// 不需要解析的键值对 的 Key
+ (NSArray *)customAcitonKeys;

// 不需要从json中解析,但是要写入本地数据库的 Key
+ (NSArray *)localKeys;

/*
    formate (?,?,?)
 */
+ (NSString *)ValuePlaceholdersWithCount:(NSUInteger)uiCount;
@end