OHMySQLQueryContext
Objective-C
@interface OHMySQLQueryContext : NSObject
Swift
class MySQLQueryContext : NSObject
An instance of this class is responsible for executing queries, saving/updating/deleting objects.
-
Initializes a context with a given parent context.
Declaration
Objective-C
- (nonnull instancetype)initWithParentQueryContext: (nullable OHMySQLQueryContext *)parentQueryContext;
Swift
init(parentQueryContext: MySQLQueryContext?)
Parameters
parentQueryContext
The parent of the context.
Return Value
Initialized context with set parent context.
-
The parent of the context.
Declaration
Objective-C
@property (strong, nullable) OHMySQLQueryContext *parentQueryContext;
Swift
var parent: MySQLQueryContext? { get set }
-
Should be set before using the class.
Declaration
Objective-C
@property (strong, nonnull) OHMySQLStoreCoordinator *storeCoordinator;
Swift
var storeCoordinator: OHMySQLStoreCoordinator { get set }
-
The set of objects that have been inserted into the context but not yet saved in a persistent store.
Declaration
Objective-C
@property (nonatomic, strong, readonly, nullable) NSSet<__kindof NSObject<OHMySQLMappingProtocol> *> *insertedObjects;
-
The set of objects that have been updated into the context but not yet saved in a persistent store.
Declaration
Objective-C
@property (nonatomic, strong, readonly, nullable) NSSet<__kindof NSObject<OHMySQLMappingProtocol> *> *updatedObjects;
-
The set of objects that have been deleted into the context but not yet saved in a persistent store.
Declaration
Objective-C
@property (nonatomic, strong, readonly, nullable) NSSet<__kindof NSObject<OHMySQLMappingProtocol> *> *deletedObjects;
-
Executes a query.
Declaration
Objective-C
- (BOOL)executeQueryRequest:(nonnull OHMySQLQueryRequest *)query error:(NSError *_Nullable *_Nullable)error;
Swift
func execute(_ query: OHMySQLQueryRequest) throws
Parameters
query
An query that should be executed.
error
The error that occurred during the attempt to execute.
-
Executes a query and returns result. This method is the most applicable for SELECT queries.
Declaration
Objective-C
- (nullable NSArray<NSDictionary<NSString *, id> *> *) executeQueryRequestAndFetchResult:(nonnull OHMySQLQueryRequest *)query error:(NSError *_Nullable *_Nullable)error;
Swift
func executeQueryRequestAndFetchResult(_ query: OHMySQLQueryRequest) throws -> [[String : Any]]
Parameters
query
An query that should be executed.
error
The error that occurred during the attempt to execute.
Return Value
Result parsed as an array of dictionaries.
-
Declaration
Objective-C
- (nonnull NSNumber *)lastInsertID;
Swift
func lastInsertID() -> NSNumber
Return Value
Returns a value representing the first automatically generated value that was set for an AUTO_INCREMENT column by the most recently executed INSERT statement to affect such a column. Returns 0, which reflects that no row was inserted. Or returns 0 if the previous statement does not use an AUTO_INCREMENT value.
-
Declaration
Objective-C
- (nullable NSNumber *)affectedRows;
Swift
func affectedRows() -> NSNumber?
Return Value
An integer greater than zero indicates the number of rows affected or retrieved. Zero indicates that no records were updated for an UPDATE statement, no rows matched the WHERE clause in the query or that no query has yet been executed. -1 indicates that the query returned an error.
-
Makes object ready to be inserted.
Declaration
Objective-C
- (void)insertObject:(nullable NSObject<OHMySQLMappingProtocol> *)object;
-
Makes object ready to be updated.
Declaration
Objective-C
- (void)updateObject:(nullable NSObject<OHMySQLMappingProtocol> *)object;
-
Makes object ready to be deleted.
Declaration
Objective-C
- (void)deleteObject:(nullable NSObject<OHMySQLMappingProtocol> *)object;
-
Removes object from deleted/inserted/updated.
Declaration
Objective-C
- (void)refreshObject:(nullable NSObject<OHMySQLMappingProtocol> *)object;
-
Attempts to commit unsaved changes.
Declaration
Objective-C
- (BOOL)save:(NSError *_Nullable *_Nullable)error;
Swift
func save() throws
Parameters
error
A pointer to an NSError object.
Return Value
YES if the save succeeds, otherwise NO.
-
Performs block asynchronously.
Declaration
Objective-C
- (void)performBlock:(nonnull dispatch_block_t)block;
Swift
func perform(_ block: @escaping () -> Void)
-
Saves to MySQL store asynchronously in global queue.
Declaration
Objective-C
- (void)saveToPersistantStore: (nonnull void (^)(NSError *_Nullable))completionHandler;
Swift
func saveToPersistantStore() async throws