NSObject+LKDBHelper.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // NSObject+LKDBHelper.h
  3. // LKDBHelper
  4. //
  5. // Created by LJH on 13-6-8.
  6. // Copyright (c) 2013年 ljh. All rights reserved.
  7. //
  8. #import "LKDBHelper.h"
  9. #import <Foundation/Foundation.h>
  10. NS_ASSUME_NONNULL_BEGIN
  11. @class LKDBHelper;
  12. @interface NSObject (LKDBHelper_Delegate)
  13. + (void)dbDidCreateTable:(LKDBHelper *)helper tableName:(NSString *)tableName;
  14. + (void)dbDidAlterTable:(LKDBHelper *)helper tableName:(NSString *)tableName addColumns:(NSArray *)columns;
  15. + (BOOL)dbWillInsert:(NSObject *)entity;
  16. + (void)dbDidInserted:(NSObject *)entity result:(BOOL)result;
  17. + (BOOL)dbWillUpdate:(NSObject *)entity;
  18. + (void)dbDidUpdated:(NSObject *)entity result:(BOOL)result;
  19. + (BOOL)dbWillDelete:(NSObject *)entity;
  20. + (void)dbDidDeleted:(NSObject *)entity result:(BOOL)result;
  21. ///data read finish
  22. + (void)dbDidSeleted:(NSObject *)entity;
  23. @end
  24. //only simplify synchronous function
  25. @interface NSObject (LKDBHelper_Execute)
  26. /**
  27. * 返回行数
  28. *
  29. * @param where type can NSDictionary or NSString
  30. *
  31. * @return row count
  32. */
  33. + (NSInteger)rowCountWithWhere:(nullable id)where, ...;
  34. + (NSInteger)rowCountWithWhereFormat:(nullable id)where, ...;
  35. /**
  36. * 搜索
  37. *
  38. * @param columns type can NSArray or NSString(Search for a specific column. Search only one, only to return the contents of the column collection)
  39. * @param where where type can NSDictionary or NSString
  40. *
  41. * @return model collection or contents of the columns collection
  42. */
  43. + (nullable NSMutableArray *)searchColumn:(nullable id)columns
  44. where:(nullable id)where
  45. orderBy:(nullable NSString *)orderBy
  46. offset:(NSInteger)offset
  47. count:(NSInteger)count;
  48. + (nullable NSMutableArray *)searchWithWhere:(nullable id)where
  49. orderBy:(nullable NSString *)orderBy
  50. offset:(NSInteger)offset
  51. count:(NSInteger)count;
  52. + (nullable NSMutableArray *)searchWithWhere:(nullable id)where;
  53. + (nullable NSMutableArray *)searchWithSQL:(NSString *)sql;
  54. + (nullable id)searchSingleWithWhere:(nullable id)where
  55. orderBy:(nullable NSString *)orderBy;
  56. + (BOOL)insertToDB:(NSObject *)model;
  57. + (BOOL)insertWhenNotExists:(NSObject *)model;
  58. + (BOOL)updateToDB:(NSObject *)model
  59. where:(nullable id)where, ...;
  60. + (BOOL)updateToDBWithSet:(NSString *)sets
  61. where:(nullable id)where, ...;
  62. + (BOOL)deleteToDB:(NSObject *)model;
  63. + (BOOL)deleteWithWhere:(nullable id)where, ...;
  64. + (BOOL)isExistsWithModel:(NSObject *)model;
  65. - (BOOL)updateToDB;
  66. - (BOOL)saveToDB;
  67. - (BOOL)deleteToDB;
  68. - (BOOL)isExistsFromDB;
  69. ///异步插入数据 async insert array , completed 也是在子线程直接回调的
  70. + (void)insertArrayByAsyncToDB:(NSArray *)models;
  71. + (void)insertArrayByAsyncToDB:(NSArray *)models completed:(void (^_Nullable)(BOOL allInserted))completedBlock;
  72. ///begin translate for insert models 开始事务插入数组
  73. + (void)insertToDBWithArray:(NSArray *)models
  74. filter:(void (^_Nullable)(id model, BOOL inserted, BOOL *_Nullable rollback))filter;
  75. + (void)insertToDBWithArray:(NSArray *)models
  76. filter:(void (^_Nullable)(id model, BOOL inserted, BOOL *_Nullable rollback))filter
  77. completed:(void (^_Nullable)(BOOL allInserted))completedBlock;
  78. @end
  79. NS_ASSUME_NONNULL_END