NSObject+LKModel.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // NSObject+LKModel.h
  3. // LKDBHelper
  4. //
  5. // Created by upin on 13-4-15.
  6. // Copyright (c) 2013年 ljh. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <objc/runtime.h>
  10. @class LKDBProperty;
  11. @class LKModelInfos;
  12. @class LKDBHelper;
  13. #pragma mark- 表结构
  14. @interface NSObject(LKTabelStructure)
  15. // overwrite in your models, return # table name #
  16. +(NSString*)getTableName;
  17. // overwrite in your models, set colume attribute
  18. +(void)columeAttributeWithProperty:(LKDBProperty*)property;
  19. /**
  20. * @brief overwrite in your models, if your table has primary key
  21. return # colume name #
  22. 主键列名 如果rowid<0 则跟据此名称update 和delete
  23. */
  24. +(NSString*)getPrimaryKey;
  25. //return multi primary key 返回联合主键
  26. +(NSArray*) getPrimaryKeyUnionArray;
  27. @property int rowid;
  28. /**
  29. * @brief get saved pictures and data file path,can overwirte
  30. 获取保存的 图片和数据的文件路径
  31. */
  32. +(NSString*)getDBImagePathWithName:(NSString*)filename;
  33. +(NSString*)getDBDataPathWithName:(NSString*)filename;
  34. @end
  35. #pragma mark- 表数据操作
  36. @interface NSObject(LKTableData)
  37. /**
  38. * @brief overwrite in your models,return insert sqlite table data
  39. *
  40. *
  41. * @return property the data after conversion
  42. */
  43. -(id)userGetValueForModel:(LKDBProperty*)property;
  44. /**
  45. * @brief overwrite in your models,return insert sqlite table data
  46. *
  47. * @param property will set property
  48. * @param value sqlite value (normal value is NSString type)
  49. */
  50. -(void)userSetValueForModel:(LKDBProperty*)property value:(id)value;
  51. //lkdbhelper use
  52. -(id)modelGetValue:(LKDBProperty*)property;
  53. -(void)modelSetValue:(LKDBProperty*)property value:(id)value;
  54. -(id)getPrimaryValue;
  55. @end
  56. @interface NSObject (LKModel)
  57. //return model use LKDBHelper , default return global LKDBHelper;
  58. +(LKDBHelper*)getUsingLKDBHelper;
  59. /**
  60. * @brief 返回 该Model 的基础信息
  61. *
  62. */
  63. +(LKModelInfos*)getModelInfos;
  64. /**
  65. * @brief Containing the super class attributes 设置是否包含 父类 的属性
  66. */
  67. +(BOOL)isContainParent;
  68. /**
  69. * @brief log all property 打印所有的属性名称和数据
  70. */
  71. -(NSString*)printAllPropertys;
  72. @end