CKKSSQLDatabaseObject.h [plain text]
#include <securityd/SecDbItem.h>
#include <utilities/SecDb.h>
#define CKKSNilToNSNull(obj) \
({ \
id o = (obj); \
o ? o : [NSNull null]; \
})
#define CKKSNSNullToNil(obj) \
({ \
id o = (obj); \
([o isEqual:[NSNull null]]) ? nil : o; \
})
#define CKKSIsNull(x) \
({ \
id y = (x); \
((y == nil) || ([y isEqual:[NSNull null]])); \
})
#define CKKSUnbase64NullableString(x) (!CKKSIsNull(x) ? [[NSData alloc] initWithBase64EncodedString:x options:0] : nil)
NS_ASSUME_NONNULL_BEGIN
@interface CKKSSQLDatabaseObject : NSObject <NSCopying>
@property (copy) NSDictionary<NSString*, NSString*>* originalSelfWhereClause;
- (bool)saveToDatabase:(NSError* _Nullable __autoreleasing* _Nullable)error;
- (bool)saveToDatabaseWithConnection:(SecDbConnectionRef _Nullable)conn
error:(NSError* _Nullable __autoreleasing* _Nullable)error;
- (bool)deleteFromDatabase:(NSError* _Nullable __autoreleasing* _Nullable)error;
+ (bool)deleteAll:(NSError* _Nullable __autoreleasing* _Nullable)error;
+ (instancetype _Nullable)fromDatabaseWhere:(NSDictionary*)whereDict error:(NSError* _Nullable __autoreleasing* _Nullable)error;
+ (instancetype _Nullable)tryFromDatabaseWhere:(NSDictionary*)whereDict
error:(NSError* _Nullable __autoreleasing* _Nullable)error;
+ (NSArray*)all:(NSError* _Nullable __autoreleasing* _Nullable)error;
+ (NSArray*)allWhere:(NSDictionary* _Nullable)whereDict error:(NSError* _Nullable __autoreleasing* _Nullable)error;
+ (NSArray*)fetch:(size_t)count error:(NSError* _Nullable __autoreleasing* _Nullable)error;
+ (NSArray*)fetch:(size_t)count
where:(NSDictionary* _Nullable)whereDict
error:(NSError* _Nullable __autoreleasing* _Nullable)error;
+ (NSArray*)fetch:(size_t)count
where:(NSDictionary* _Nullable)whereDict
orderBy:(NSArray* _Nullable)orderColumns
error:(NSError* _Nullable __autoreleasing* _Nullable)error;
+ (bool)saveToDatabaseTable:(NSString*)table
row:(NSDictionary*)row
connection:(SecDbConnectionRef _Nullable)dbconn
error:(NSError* _Nullable __autoreleasing* _Nullable)error;
+ (bool)deleteFromTable:(NSString*)table
where:(NSDictionary* _Nullable)whereDict
connection:(SecDbConnectionRef _Nullable)dbconn
error:(NSError* _Nullable __autoreleasing* _Nullable)error;
+ (bool)queryDatabaseTable:(NSString*)table
where:(NSDictionary* _Nullable)whereDict
columns:(NSArray*)names
groupBy:(NSArray* _Nullable)groupColumns
orderBy:(NSArray* _Nullable)orderColumns
limit:(ssize_t)limit
processRow:(void (^)(NSDictionary*))processRow
error:(NSError* _Nullable __autoreleasing* _Nullable)error;
+ (bool)queryMaxValueForField:(NSString*)maxField
inTable:(NSString*)table
where:(NSDictionary* _Nullable)whereDict
columns:(NSArray*)names
processRow:(void (^)(NSDictionary*))processRow;
- (instancetype)memoizeOriginalSelfWhereClause;
#pragma mark - Subclasses must implement the following:
+ (instancetype _Nullable)fromDatabaseRow:(NSDictionary*)row;
+ (NSArray<NSString*>*)sqlColumns;
+ (NSString*)sqlTable;
- (NSDictionary<NSString*, NSString*>*)sqlValues;
- (NSDictionary<NSString*, NSString*>*)whereClauseToFindSelf;
@end
@interface CKKSSQLWhereObject : NSObject
@property NSString* sqlOp;
@property NSString* contents;
- (instancetype)initWithOperation:(NSString*)op string:(NSString*)str;
+ (instancetype)op:(NSString*)op string:(NSString*)str;
+ (instancetype)op:(NSString*)op stringValue:(NSString*)str; @end
NS_ASSUME_NONNULL_END