CKKSSQLDatabaseObject.h [plain text]
#ifndef DatabaseObject_h
#define DatabaseObject_h
#include <utilities/SecDb.h>
#include <securityd/SecDbItem.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)
@interface CKKSSQLDatabaseObject : NSObject <NSCopying> {
}
@property (copy) NSDictionary<NSString*,NSString*>* originalSelfWhereClause;
- (bool) saveToDatabase: (NSError * __autoreleasing *) error;
- (bool) saveToDatabaseWithConnection: (SecDbConnectionRef) conn error: (NSError * __autoreleasing *) error;
- (bool) deleteFromDatabase: (NSError * __autoreleasing *) error;
+ (bool) deleteAll: (NSError * __autoreleasing *) error;
+ (instancetype) fromDatabaseWhere: (NSDictionary*) whereDict error: (NSError * __autoreleasing *) error;
+ (instancetype) tryFromDatabaseWhere: (NSDictionary*) whereDict error: (NSError * __autoreleasing *) error;
+ (NSArray*) all: (NSError * __autoreleasing *) error;
+ (NSArray*) allWhere: (NSDictionary*) whereDict error: (NSError * __autoreleasing *) error;
+ (NSArray*)fetch:(size_t)count error: (NSError * __autoreleasing *) error;
+ (NSArray*)fetch:(size_t)count where:(NSDictionary*)whereDict error: (NSError * __autoreleasing *) error;
+ (NSArray*)fetch: (size_t)count where:(NSDictionary*)whereDict orderBy:(NSArray*) orderColumns error: (NSError * __autoreleasing *) error;
+ (bool) saveToDatabaseTable: (NSString*) table row: (NSDictionary*) row connection: (SecDbConnectionRef) dbconn error: (NSError * __autoreleasing *) error;
+ (bool) deleteFromTable: (NSString*) table where: (NSDictionary*) whereDict connection:(SecDbConnectionRef) dbconn error: (NSError * __autoreleasing *) error;
+ (bool) queryDatabaseTable:(NSString*) table
where:(NSDictionary*) whereDict
columns:(NSArray*) names
groupBy:(NSArray*) groupColumns
orderBy:(NSArray*) orderColumns
limit:(ssize_t)limit
processRow:(void (^)(NSDictionary*)) processRow
error:(NSError * __autoreleasing *) error;
+ (bool)queryMaxValueForField:(NSString*)maxField inTable:(NSString*)table where:(NSDictionary*)whereDict columns:(NSArray*)names processRow:(void (^)(NSDictionary*))processRow;
- (instancetype) memoizeOriginalSelfWhereClause;
#pragma mark - Subclasses must implement the following:
+ (instancetype) fromDatabaseRow: (NSDictionary*) row;
+ (NSArray<NSString*>*) sqlColumns;
+ (NSString*) sqlTable;
- (NSDictionary<NSString*,NSString*>*) sqlValues;
- (NSDictionary<NSString*,NSString*>*) whereClauseToFindSelf;
- (instancetype)copyWithZone:(NSZone *)zone;
@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
#endif