OHMySQLQueryRequestFactory

Objective-C


@interface OHMySQLQueryRequestFactory : NSObject

Swift

class MySQLQueryRequestFactory : NSObject

Convenience class for making specific OHMySQLQueryRequest instances.

SELECT

  • Select all records.

    Declaration

    Objective-C

    + (nonnull OHMySQLQueryRequest *)SELECT:(nonnull NSString *)tableName
                                  condition:(nullable NSString *)condition;

    Swift

    class func select(_ tableName: String, condition: String?) -> OHMySQLQueryRequest

    Parameters

    tableName

    Name of the target table.

    condition

    Likes in real SQL query (e.g: WHERE id=‘10’). https://en.wikipedia.org/wiki/Where_%28SQL%29

    Return Value

    An instance of OHMySQLQueryRequest.

  • Select all records with sorting.

    Declaration

    Objective-C

    + (nonnull OHMySQLQueryRequest *)SELECT:(nonnull NSString *)tableName
                                  condition:(nullable NSString *)condition
                                    orderBy:
                                        (nonnull NSArray<NSString *> *)columnNames
                                  ascending:(BOOL)isAscending;

    Swift

    class func select(_ tableName: String, condition: String?, orderBy columnNames: [String], ascending isAscending: Bool) -> OHMySQLQueryRequest

    Parameters

    tableName

    Name of the target table.

    condition

    Likes in real SQL query (e.g: WHERE id=‘10’). https://en.wikipedia.org/wiki/Where_%28SQL%29

    columnNames

    Result-set of one or more columns.

    isAscending

    Ascending or descending order.

    Return Value

    An instance of OHMySQLQueryRequest.

  • Select the first record of the selected table.

    Declaration

    Objective-C

    + (nonnull OHMySQLQueryRequest *)SELECTFirst:(nonnull NSString *)tableName
                                       condition:(nullable NSString *)condition;

    Swift

    class func selectFirst(_ tableName: String, condition: String?) -> OHMySQLQueryRequest

    Parameters

    tableName

    Name of the target table.

    condition

    Likes in real SQL query (e.g: WHERE id=‘10’). https://en.wikipedia.org/wiki/Where_%28SQL%29

    Return Value

    An instance of OHMySQLQueryRequest.

  • Select the first record of the selected table.

    Declaration

    Objective-C

    + (nonnull OHMySQLQueryRequest *)
        SELECTFirst:(nonnull NSString *)tableName
          condition:(nullable NSString *)condition
            orderBy:(nonnull NSArray<NSString *> *)columnNames
          ascending:(BOOL)isAscending;

    Swift

    class func selectFirst(_ tableName: String, condition: String?, orderBy columnNames: [String], ascending isAscending: Bool) -> OHMySQLQueryRequest

    Parameters

    tableName

    Name of the target table.

    condition

    Likes in real SQL query (e.g: WHERE id=‘10’). https://en.wikipedia.org/wiki/Where_%28SQL%29

    columnNames

    Result-set of one or more columns.

    isAscending

    Ascending or descending order.

    Return Value

    An instance of OHMySQLQueryRequest.

INSERT

  • Insert a new record.

    Declaration

    Objective-C

    + (nonnull OHMySQLQueryRequest *)INSERT:(nonnull NSString *)tableName
                                        set:(nonnull NSDictionary<NSString *, id> *)
                                                set;

    Swift

    class func insert(_ tableName: String, set: [String : Any]) -> OHMySQLQueryRequest

    Parameters

    tableName

    Name of the target table.

    set

    Key is column’ name in table, value is your object.

    Return Value

    An instance of OHMySQLQueryRequest.

UPDATE

  • Update all records with condition.

    Declaration

    Objective-C

    + (nonnull OHMySQLQueryRequest *)
           UPDATE:(nonnull NSString *)tableName
              set:(nonnull NSDictionary<NSString *, id> *)set
        condition:(nullable NSString *)condition;

    Swift

    class func update(_ tableName: String, set: [String : Any], condition: String?) -> OHMySQLQueryRequest

    Parameters

    tableName

    Name of the target table.

    set

    Key is column’ name in table, value is your object.

    condition

    Likes in real SQL query (e.g: WHERE name=‘Name’). https://en.wikipedia.org/wiki/Where_%28SQL%29

    Return Value

    An instance of OHMySQLQueryRequest.

DELETE

JOIN

  • Combines rows from two or more tables, based on a common field between them.

    Declaration

    Objective-C

    + (nonnull OHMySQLQueryRequest *)
           JOINType:(nonnull NSString *)joinType
          fromTable:(nonnull NSString *)tableName
        columnNames:(nonnull NSArray<NSString *> *)columnNames
             joinOn:(nonnull NSDictionary<NSString *, NSString *> *)joinOn;

    Swift

    class func joinType(_ joinType: String, fromTable tableName: String, columnNames: [String], joinOn: [String : String]) -> OHMySQLQueryRequest

    Parameters

    joinType

    Type of join (Use one of the constants from OHJoinConstants).

    tableName

    Destination table.

    columnNames

    Columns to fetch.

    joinOn

    [Table:Condition]. { “Users”:“Users.id=Company.userId” }

    Return Value

    An instance of OHMySQLQueryRequest.

Other

  • Counts records in a table.

    Declaration

    Objective-C

    + (nonnull OHMySQLQueryRequest *)countAll:(nonnull NSString *)tableName;

    Swift

    class func countAll(_ tableName: String) -> OHMySQLQueryRequest

    Parameters

    tableName

    Name of the target table

    Return Value

    An instance of OHMySQLQueryRequest.