LKDB+Mapping.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // LKDBProperty+KeyMapping.h
  3. // LKDBHelper
  4. //
  5. // Created by upin on 13-6-17.
  6. // Copyright (c) 2013年 ljh. All rights reserved.
  7. //
  8. #import "LKDBUtils.h"
  9. static NSString* const LKSQLText = @"text";
  10. static NSString* const LKSQLInt = @"integer";
  11. static NSString* const LKSQLDouble = @"double";
  12. static NSString* const LKSQLBlob = @"blob";
  13. static NSString* const LKSQLNotNull = @"NOT NULL";
  14. static NSString* const LKSQLPrimaryKey = @"PRIMARY KEY";
  15. static NSString* const LKSQLDefault = @"DEFAULT";
  16. static NSString* const LKSQLUnique = @"UNIQUE";
  17. static NSString* const LKSQLCheck = @"CHECK";
  18. static NSString* const LKSQLForeignKey = @"FOREIGN KEY";
  19. static NSString* const LKSQLFloatType = @"float_double_decimal";
  20. static NSString* const LKSQLIntType = @"int_char_short_long";
  21. static NSString* const LKSQLBlobType = @"";
  22. static NSString* const LKSQLInherit = @"LKDBInherit";
  23. static NSString* const LKSQLBinding = @"LKDBBinding";
  24. static NSString* const LKSQLUserCalculate = @"LKDBUserCalculate";
  25. //Object-c type converted to SQLite type 把Object-c 类型 转换为sqlite 类型
  26. extern inline NSString* LKSQLTypeFromObjcType(NSString *objcType);
  27. @interface NSObject(TableMapping)
  28. /**
  29. * @brief Overwrite in your models if your property names don't match your Table Colume names.
  30. also use for set create table columes.
  31. @{ sql colume name : ( model property name ) or LKDBInherit or LKDBUserCalculate}
  32. */
  33. +(NSDictionary*)getTableMapping;
  34. //simple set a colume as "LKSQLUserCalculate"
  35. //colume name
  36. +(void)setUserCalculateForCN:(NSString*)columename;
  37. //property type name
  38. +(void)setUserCalculateForPTN:(NSString*)propertyTypeName;
  39. //remove unwanted binding property
  40. +(void)removePropertyWithColumeName:(NSString*)columename;
  41. @end
  42. @interface LKDBProperty:NSObject
  43. @property(readonly,nonatomic)NSString* type;
  44. @property(readonly,nonatomic)NSString* sqlColumeName;
  45. @property(readonly,nonatomic)NSString* sqlColumeType;
  46. @property(readonly,nonatomic)NSString* propertyName;
  47. @property(readonly,nonatomic)NSString* propertyType;
  48. //创建表的时候 使用
  49. @property BOOL isUnique;
  50. @property BOOL isNotNull;
  51. @property(strong,nonatomic) NSString* defaultValue;
  52. @property(strong,nonatomic) NSString* checkValue;
  53. @property int length;
  54. -(BOOL)isUserCalculate;
  55. @end
  56. @interface LKModelInfos : NSObject
  57. -(id)initWithKeyMapping:(NSDictionary*)keyMapping propertyNames:(NSArray*)propertyNames propertyType:(NSArray*)propertyType primaryKeys:(NSArray*)primaryKeys;
  58. @property(readonly,nonatomic)int count;
  59. @property(readonly,nonatomic)NSArray* primaryKeys;
  60. -(LKDBProperty*)objectWithIndex:(int)index;
  61. -(LKDBProperty*)objectWithPropertyName:(NSString*)propertyName;
  62. -(LKDBProperty*)objectWithSqlColumeName:(NSString*)columeName;
  63. @end