ConnectionPoolConnection

public class ConnectionPoolConnection : Connection

Note: This class is usually initialised by the ConnectionPool instance. Therefore, a standard user will not use this class unless they are creating their own SQL plugin.

This class uses a Connection instance and a ConnectionPool instance to implement a wrapper for the Connection class. It implements the functions of the Connection protocol, in addition to the closeConnection() function for releasing a Connection instance from the ConnectionPool.

Usage Example:

In this example, a ConnectionPool instance is initialized (parameters defined in docs for ConnectionPool). A ConnectionPoolConnection instance is created by calling connectionPool.getConnection(). This connection is then released from the pool.

let connectionPool = ConnectionPool(options: options, connectionGenerator: connectionGenerator, connectionReleaser: connectionReleaser)
let connection = connectionPool.getConnection()
connection.closeConnection()

QueryBuilder

Connections

  • Establish a connection with the database.

    Declaration

    Swift

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

    Parameters

    onCompletion

    The function to be called when the connection is established.

  • Establish a connection with the database.

    Declaration

    Swift

    public func connectSync() -> QueryResult

    Return Value

    A QueryError if the connection cannot connect, otherwise nil

  • Close the connection to the database.

    Usage Example:

    In this example, the closeConnection() function is called on a ConnectionPoolConnection instance to release it from its ConnectionPool instance.

    connection.closeConnection()
    

    Declaration

    Swift

    public func closeConnection()
  • An indication whether there is a connection to the database.

    Usage Example:

    In this example, the isConnected() function is called on a ConnectionPoolConnection instance called connection, this returns a true value that is then printed.

    let connected = connection.isConnected()
    print(connected)
    // Prints true
    

    Declaration

    Swift

    public var isConnected: Bool { get }

    Return Value

    A boolean value, for whether the connection is connected.

Execute Querys

  • Execute a query.

    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 raw query.

    Declaration

    Swift

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

    Parameters

    raw

    A string that contains the query to execute.

    onCompletion

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

  • Execute a query with parameters.

    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 raw query with parameters.

    Declaration

    Swift

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

    Parameters

    raw

    A string that contains 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 with parameters.

    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.

  • Execute a raw query with parameters.

    Declaration

    Swift

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

    Parameters

    raw

    A string that contains 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.

Prepared statements

  • Create a prepared statement from the passed in query.

    Declaration

    Swift

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

    Parameters

    query

    The query to prepare the statement for.

    onCompletion

    The function to be called when the preparation has completed.

  • Create a prepared statement from the passed in query.

    Declaration

    Swift

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

    Parameters

    raw

    A String containing the query to prepare the statement for.

    onCompletion

    The function to be called when the preparation has completed.

  • Execute a prepared statement.

    Declaration

    Swift

    public func execute(preparedStatement: PreparedStatement, onCompletion: @escaping ((QueryResult) -> ()))

    Parameters

    preparedStatement

    The prepared statement to execute.

    onCompletion

    The function to be called when the execution has completed.

  • Execute a prepared statement with parameters.

    Declaration

    Swift

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

    Parameters

    preparedStatement

    The prepared statement to execute.

    parameters

    An array of the parameters.

    onCompletion

    The function to be called when the execution has completed.

  • Execute a prepared statement with parameters.

    Declaration

    Swift

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

    Parameters

    preparedStatement

    The prepared statement to execute.

    parameters

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

    onCompletion

    The function to be called when the execution has completed.

  • Release a prepared statement.

    Declaration

    Swift

    public func release(preparedStatement: PreparedStatement, onCompletion: @escaping ((QueryResult) -> ()))

    Parameters

    preparedStatement

    The prepared statement to release.

    onCompletion

    The function to be called when the execution has completed.

  • Return a String representation of the query.

    Throws

    QueryError.syntaxError if the query build fails.

    Declaration

    Swift

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

    Parameters

    query

    The query.

    Return Value

    A String representation of the query.

Transactions

  • Start a transaction.

    Declaration

    Swift

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

    Parameters

    onCompletion

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

  • Commit the current transaction.

    Declaration

    Swift

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

    Parameters

    onCompletion

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

  • Rollback the current transaction.

    Declaration

    Swift

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

    Parameters

    onCompletion

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

  • Create a savepoint.

    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 the create savepoint command has completed.

  • Rollback the current transaction to the specified savepoint.

    Declaration

    Swift

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

    Parameters

    onCompletion

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

  • Release a savepoint.

    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 the release savepoint command has completed.