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
QueryBuilderwith 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 localhostParameter
Parameter user: MySQL login ID, defaults to current userParameter
Parameter password: password foruser, defaults to no passwordParameter
Parameter database: default database to use if specifiedParameter
Parameter port: port number for the TCP/IP connection if using a non-standard portParameter
Parameter unixSocket: unix domain socket or named pipe to use for connecting to server instead of TCP/IPParameter
Parameter clientFlag: MySQL client optionsParameter
Parameter characterSet: MySQL character set to use for the connectionDeclaration
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
hosthost name or IP address of server to connect to, defaults to localhost
userMySQL login ID, defaults to current user
passwordpassword for
user, defaults to no passworddatabasedefault database to use if specified
portport number for the TCP/IP connection if using a non-standard port
unixSocketunix domain socket or named pipe to use for connecting to server instead of TCP/IP
clientFlagMySQL client options
characterSetMySQL 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/databaseDeclaration
Swift
public convenience init(url: URL)Parameters
urlA 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 localhostParameter
Parameter user: MySQL login ID, defaults to current userParameter
Parameter password: password foruser, defaults to no passwordParameter
Parameter database: default database to use if specifiedParameter
Parameter port: port number for the TCP/IP connection if using a non-standard portParameter
Parameter unixSocket: unix domain socket or named pipe to use for connecting to server instead of TCP/IPParameter
Parameter clientFlag: MySQL client optionsParameter
Parameter characterSet: MySQL character set to use for the connectionParameter
Parameter poolOptions: A set ofConnectionOptionsto pass to the MySQL server.Returns
ConnectionPoolofMySQLConnection.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) -> ConnectionPoolParameters
hosthost name or IP address of server to connect to, defaults to localhost
userMySQL login ID, defaults to current user
passwordpassword for
user, defaults to no passworddatabasedefault database to use if specified
portport number for the TCP/IP connection if using a non-standard port
unixSocketunix domain socket or named pipe to use for connecting to server instead of TCP/IP
clientFlagMySQL client options
characterSetMySQL character set to use for the connection
poolOptionsA set of
ConnectionOptionsto pass to the MySQL server.Return Value
ConnectionPoolofMySQLConnection. -
Create a MySQL connection pool.
Parameter
Parameter url: A URL with the connection information. For example, mysql://user:password@host:port/databaseParameter
Parameter poolOptions: A set ofConnectionOptionsto pass to the MySQL server.Returns
ConnectionPoolofMySQLConnection.Declaration
Swift
public static func createPool(url: URL, poolOptions: ConnectionPoolOptions) -> ConnectionPoolParameters
urlA URL with the connection information. For example, mysql://user:password@host:port/database
poolOptionsA set of
ConnectionOptionsto pass to the MySQL server.Return Value
ConnectionPoolofMySQLConnection. -
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
onCompletionThe 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 -> StringParameters
queryThe 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
queryThe query to execute.
onCompletionThe 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
queryThe query to execute.
parametersAn array of the parameters.
onCompletionThe 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
queryThe query to execute.
parametersMultiple sets of parameters.
onCompletionThe 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
queryA String with the query to execute.
onCompletionThe 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
queryA String with the query to execute.
parametersAn array of the parameters.
onCompletionThe 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
queryA String with the query to execute.
parametersMultiple sets of parameters.
onCompletionThe 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
queryThe query to execute.
parametersA dictionary of the parameters with parameter names as the keys.
onCompletionThe 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
queryA String with the query to execute.
parametersA dictionary of the parameters with parameter names as the keys.
onCompletionThe 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
onCompletionThe 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
onCompletionThe 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
onCompletionThe 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
savepointThe name to be given to the created savepoint.
onCompletionThe 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 savepointThe name of the savepoint to rollback to.
onCompletionThe 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
savepointThe name of the savepoint to release.
onCompletionThe function to be called when the execution of release savepoint command has completed.
View on GitHub
MySQLConnection Class Reference