NSObject+LKModel.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // NSObject+LKModel.h
  3. // LKDBHelper
  4. //
  5. // Created by LJH on 13-4-15.
  6. // Copyright (c) 2013年 ljh. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. NS_ASSUME_NONNULL_BEGIN
  10. @class LKDBProperty;
  11. @class LKModelInfos;
  12. @class LKDBHelper;
  13. #pragma mark - 表结构
  14. @interface NSObject (LKTabelStructure)
  15. /**
  16. * overwrite in your models(option)
  17. *
  18. * @return # table name #
  19. */
  20. + (NSString *)getTableName;
  21. /**
  22. * if you set it will use it as a table name
  23. */
  24. @property (nullable, nonatomic, copy) NSString *db_tableName;
  25. /**
  26. * the model is inserting ..
  27. */
  28. @property (nonatomic, readonly) BOOL db_inserting;
  29. /**
  30. * sqlite comes with rowid
  31. */
  32. @property (nonatomic, assign) NSInteger rowid;
  33. /**
  34. * overwrite in your models, if your table has primary key
  35. * 主键列名 如果rowid<0 则跟据此名称update 和delete
  36. * @return # column name #
  37. */
  38. + (nullable NSString *)getPrimaryKey;
  39. /**
  40. * multi primary key
  41. * 联合主键
  42. */
  43. + (nullable NSArray *)getPrimaryKeyUnionArray;
  44. /**
  45. * overwrite in your models set column attribute
  46. *
  47. * @param property infos
  48. */
  49. + (void)columnAttributeWithProperty:(LKDBProperty *)property;
  50. /**
  51. * @brief get saved pictures and data file path,can overwirte
  52. 获取保存的 图片和数据的文件路径
  53. */
  54. + (NSString *)getDBImagePathWithName:(NSString *)filename;
  55. + (NSString *)getDBDataPathWithName:(NSString *)filename;
  56. @end
  57. #pragma mark - 表数据操作
  58. @interface NSObject (LKTableData)
  59. /***
  60. * @brief overwrite in your models,return insert sqlite table data
  61. *
  62. *
  63. * @return property the data after conversion
  64. */
  65. - (nullable id)userGetValueForModel:(LKDBProperty *)property;
  66. /***
  67. * @brief overwrite in your models,return insert sqlite table data
  68. *
  69. * @param property will set property
  70. * @param value sqlite value (NSString(NSData UTF8 Coding) or NSData)
  71. */
  72. - (void)userSetValueForModel:(LKDBProperty *)property value:(nullable id)value;
  73. ///overwrite
  74. + (NSDateFormatter *)getModelDateFormatter;
  75. //lkdbhelper use
  76. - (nullable id)modelGetValue:(LKDBProperty *)property;
  77. - (void)modelSetValue:(LKDBProperty *)property value:(nullable NSString *)value;
  78. - (nullable id)singlePrimaryKeyValue;
  79. - (BOOL)singlePrimaryKeyValueIsEmpty;
  80. - (nullable LKDBProperty *)singlePrimaryKeyProperty;
  81. + (nullable NSString *)db_rowidAliasName;
  82. @end
  83. @interface NSObject (LKModel)
  84. /**
  85. * return model use LKDBHelper , default return global LKDBHelper;
  86. *
  87. * @return LKDBHelper
  88. */
  89. + (LKDBHelper *)getUsingLKDBHelper;
  90. /**
  91. * class attributes
  92. *
  93. * @return LKModelInfos
  94. */
  95. + (LKModelInfos *)getModelInfos;
  96. /**
  97. * @brief Containing the super class attributes 设置是否包含 父类 的属性
  98. */
  99. + (BOOL)isContainParent;
  100. /**
  101. * 当前表中的列是否包含自身的属性。
  102. *
  103. * @return BOOL
  104. */
  105. + (BOOL)isContainSelf;
  106. /**
  107. * @brief log all property 打印所有的属性名称和数据
  108. */
  109. - (NSString *)printAllPropertys;
  110. - (NSString *)printAllPropertysIsContainParent:(BOOL)containParent;
  111. - (NSMutableString *)getAllPropertysString;
  112. @end
  113. NS_ASSUME_NONNULL_END