MySQLConnection

public class MySQLConnection: Connection

An implementation of SwiftKuery.Connection protocol for MySQL. Instances of MySQLConnection are NOT thread-safe and should not be shared between threads. Use MySQLThreadSafeConnection to share connection instances between multiple threads.

  • Declaration

    Swift

    public var isConnected: Bool
  • The QueryBuilder with MySQL specific substitutions.

    Declaration

    Swift

    public let queryBuilder: QueryBuilder =
  • Initialize an instance of MySQLConnection.

    Parameter

    Parameter host: host name or IP address of server to connect to, defaults to localhost

    Parameter

    Parameter user: MySQL login ID, defaults to current user

    Parameter

    Parameter password: password for user, defaults to no password

    Parameter

    Parameter database: default database to use if specified

    Parameter

    Parameter port: port number for the TCP/IP connection if using a non-standard port

    Parameter

    Parameter unixSocket: unix domain socket or named pipe to use for connecting to server instead of TCP/IP

    Parameter

    Parameter clientFlag: MySQL client options

    Parameter

    Parameter characterSet: MySQL character set to use for the connection

    Declaration

    Swift

    public required init(host: String? = nil, user: String? = nil, password: String? = nil, database: String? = nil, port: Int? = nil, unixSocket: String? = nil, clientFlag: UInt = 0, characterSet: String? = nil)

    Parameters

    host

    host name or IP address of server to connect to, defaults to localhost

    user

    MySQL login ID, defaults to current user

    password

    password for user, defaults to no password

    database

    default database to use if specified

    port

    port number for the TCP/IP connection if using a non-standard port

    unixSocket

    unix domain socket or named pipe to use for connecting to server instead of TCP/IP

    clientFlag

    MySQL client options

    characterSet

    MySQL character set to use for the connection

  • Initialize an instance of MySQLConnection.

    Parameter

    Parameter url: A URL with the connection information. For example, mysql://user:password@host:port/database

    Declaration

    Swift

    public convenience init(url: URL)

    Parameters

    url

    A URL with the connection information. For example, mysql://user:password@host:port/database

  • Create a MySQL connection pool.

    Parameter

    Parameter host: host name or IP address of server to connect to, defaults to localhost

    Parameter

    Parameter user: MySQL login ID, defaults to current user

    Parameter

    Parameter password: password for user, defaults to no password

    Parameter

    Parameter database: default database to use if specified

    Parameter

    Parameter port: port number for the TCP/IP connection if using a non-standard port

    Parameter

    Parameter unixSocket: unix domain socket or named pipe to use for connecting to server instead of TCP/IP

    Parameter

    Parameter clientFlag: MySQL client options

    Parameter

    Parameter characterSet: MySQL character set to use for the connection

    Parameter

    Parameter poolOptions: A set of ConnectionOptions to pass to the MySQL server.

    Returns

    ConnectionPool of MySQLConnection.

    Declaration

    Swift

    public static func createPool(host: String? = nil, user: String? = nil, password: String? = nil, database: String? = nil, port: Int? = nil, unixSocket: String? = nil, clientFlag: UInt = 0, characterSet: String? = nil, poolOptions: ConnectionPoolOptions) -> ConnectionPool

    Parameters

    host

    host name or IP address of server to connect to, defaults to localhost

    user

    MySQL login ID, defaults to current user

    password

    password for user, defaults to no password

    database

    default database to use if specified

    port

    port number for the TCP/IP connection if using a non-standard port

    unixSocket

    unix domain socket or named pipe to use for connecting to server instead of TCP/IP

    clientFlag

    MySQL client options

    characterSet

    MySQL character set to use for the connection

    poolOptions

    A set of ConnectionOptions to pass to the MySQL server.

    Return Value

    ConnectionPool of MySQLConnection.

  • Create a MySQL connection pool.

    Parameter

    Parameter url: A URL with the connection information. For example, mysql://user:password@host:port/database

    Parameter

    Parameter poolOptions: A set of ConnectionOptions to pass to the MySQL server.

    Returns

    ConnectionPool of MySQLConnection.

    Declaration

    Swift

    public static func createPool(url: URL, poolOptions: ConnectionPoolOptions) -> ConnectionPool

    Parameters

    url

    A URL with the connection information. For example, mysql://user:password@host:port/database

    poolOptions

    A set of ConnectionOptions to pass to the MySQL server.

    Return Value

    ConnectionPool of MySQLConnection.

  • Establish a connection with the database.

    Parameter

    Parameter onCompletion: The function to be called when the connection is established.

    Declaration

    Swift

    public func connect(onCompletion: (QueryError?) -> ())

    Parameters

    onCompletion

    The function to be called when the connection is established.

  • Close the connection to the database.

    Declaration

    Swift

    public func closeConnection()
  • Return a String representation of the query.

    Parameter

    Parameter query: The query.

    Returns

    A String representation of the query.

    Throws

    QueryError.syntaxError if query build fails.

    Declaration

    Swift

    public func descriptionOf(query: Query) throws -> String

    Parameters

    query

    The query.

    Return Value

    A String representation of the query.

  • Execute a query.

    Parameter

    Parameter query: The query to execute.

    Parameter

    Parameter onCompletion: The function to be called when the execution of the query has completed.

    Declaration

    Swift

    public func execute(query: Query, onCompletion: @escaping ((QueryResult) -> ()))

    Parameters

    query

    The query to execute.

    onCompletion

    The function to be called when the execution of the query has completed.

  • Execute a query with parameters.

    Parameter

    Parameter query: The query to execute.

    Parameter

    Parameter parameters: An array of the parameters.

    Parameter

    Parameter onCompletion: The function to be called when the execution of the query has completed.

    Declaration

    Swift

    public func execute(query: Query, parameters: [Any?], onCompletion: @escaping ((QueryResult) -> ()))

    Parameters

    query

    The query to execute.

    parameters

    An array of the parameters.

    onCompletion

    The function to be called when the execution of the query has completed.

  • Execute a query multiple times with multiple parameter sets.

    Parameter

    Parameter query: The query to execute.

    Parameter

    Parameter parameters: Multiple sets of parameters.

    Parameter

    Parameter onCompletion: The function to be called when the execution of the query has completed.

    Declaration

    Swift

    public func execute(query: Query, parametersArray: [[Any?]], onCompletion: @escaping ((QueryResult) -> ()))

    Parameters

    query

    The query to execute.

    parameters

    Multiple sets of parameters.

    onCompletion

    The function to be called when the execution of the query has completed.

  • Execute a raw query.

    Parameter

    Parameter query: A String with the query to execute.

    Parameter

    Parameter onCompletion: The function to be called when the execution of the query has completed.

    Declaration

    Swift

    public func execute(_ raw: String, onCompletion: @escaping ((QueryResult) -> ()))

    Parameters

    query

    A String with the query to execute.

    onCompletion

    The function to be called when the execution of the query has completed.

  • Execute a raw query with parameters.

    Parameter

    Parameter query: A String with the query to execute.

    Parameter

    Parameter parameters: An array of the parameters.

    Parameter

    Parameter onCompletion: The function to be called when the execution of the query has completed.

    Declaration

    Swift

    public func execute(_ raw: String, parameters: [Any?], onCompletion: @escaping ((QueryResult) -> ()))

    Parameters

    query

    A String with the query to execute.

    parameters

    An array of the parameters.

    onCompletion

    The function to be called when the execution of the query has completed.

  • Execute a raw query multiple times with multiple parameter sets.

    Parameter

    Parameter query: A String with the query to execute.

    Parameter

    Parameter parameters: Multiple sets of parameters.

    Parameter

    Parameter onCompletion: The function to be called when the execution of the query has completed.

    Declaration

    Swift

    public func execute(_ raw: String, parametersArray: [[Any?]], onCompletion: @escaping ((QueryResult) -> ()))

    Parameters

    query

    A String with the query to execute.

    parameters

    Multiple sets of parameters.

    onCompletion

    The function to be called when the execution of the query has completed.

  • NOT supported in MySQL Execute a query with named parameters.

    Parameter

    Parameter query: The query to execute.

    Parameter

    Parameter parameters: A dictionary of the parameters with parameter names as the keys.

    Parameter

    Parameter onCompletion: The function to be called when the execution of the query has completed.

    Declaration

    Swift

    public func execute(query: Query, parameters: [String:Any?], onCompletion: @escaping ((QueryResult) -> ()))

    Parameters

    query

    The query to execute.

    parameters

    A dictionary of the parameters with parameter names as the keys.

    onCompletion

    The function to be called when the execution of the query has completed.

  • NOT supported in MySQL Execute a raw query with named parameters.

    Parameter

    Parameter query: A String with the query to execute.

    Parameter

    Parameter parameters: A dictionary of the parameters with parameter names as the keys.

    Parameter

    Parameter onCompletion: The function to be called when the execution of the query has completed.

    Declaration

    Swift

    public func execute(_ raw: String, parameters: [String:Any?], onCompletion: @escaping ((QueryResult) -> ()))

    Parameters

    query

    A String with the query to execute.

    parameters

    A dictionary of the parameters with parameter names as the keys.

    onCompletion

    The function to be called when the execution of the query has completed.

  • Start a transaction.

    Parameter

    Parameter onCompletion: The function to be called when the execution of start transaction command has completed.

    Declaration

    Swift

    public func startTransaction(onCompletion: @escaping ((QueryResult) -> ()))

    Parameters

    onCompletion

    The function to be called when the execution of start transaction command has completed.

  • Commit the current transaction.

    Parameter

    Parameter onCompletion: The function to be called when the execution of commit transaction command has completed.

    Declaration

    Swift

    public func commit(onCompletion: @escaping ((QueryResult) -> ()))

    Parameters

    onCompletion

    The function to be called when the execution of commit transaction command has completed.

  • Rollback the current transaction.

    Parameter

    Parameter onCompletion: The function to be called when the execution of rolback transaction command has completed.

    Declaration

    Swift

    public func rollback(onCompletion: @escaping ((QueryResult) -> ()))

    Parameters

    onCompletion

    The function to be called when the execution of rolback transaction command has completed.

  • Create a savepoint.

    Parameter

    Parameter savepoint: The name to be given to the created savepoint.

    Parameter

    Parameter onCompletion: The function to be called when the execution of create savepoint command has completed.

    Declaration

    Swift

    public func create(savepoint: String, onCompletion: @escaping ((QueryResult) -> ()))

    Parameters

    savepoint

    The name to be given to the created savepoint.

    onCompletion

    The function to be called when the execution of create savepoint command has completed.

  • Rollback the current transaction to the specified savepoint.

    Parameter

    Parameter to savepoint: The name of the savepoint to rollback to.

    Parameter

    Parameter onCompletion: The function to be called when the execution of rolback transaction command has completed.

    Declaration

    Swift

    public func rollback(to savepoint: String, onCompletion: @escaping ((QueryResult) -> ()))

    Parameters

    to savepoint

    The name of the savepoint to rollback to.

    onCompletion

    The function to be called when the execution of rolback transaction command has completed.

  • Release a savepoint.

    Parameter

    Parameter savepoint: The name of the savepoint to release.

    Parameter

    Parameter onCompletion: The function to be called when the execution of release savepoint command has completed.

    Declaration

    Swift

    public func release(savepoint: String, onCompletion: @escaping ((QueryResult) -> ()))

    Parameters

    savepoint

    The name of the savepoint to release.

    onCompletion

    The function to be called when the execution of release savepoint command has completed.