PostgreSQLConnection
public class PostgreSQLConnection : Connection
An implementation of SwiftKuery.Connection protocol for PostgreSQL.
Please see PostgreSQL manual for details.
-
An indication whether there is a connection to the database.
Declaration
Swift
public var isConnected: Bool { get } -
The
QueryBuilderwith PostgreSQL specific substitutions.Declaration
Swift
public var queryBuilder: QueryBuilder -
Initialize an instance of PostgreSQLConnection.
Declaration
Swift
public convenience init(host: String, port: Int32, options: [ConnectionOptions]?)Parameters
hostThe host of the PostgreSQL server to connect to.
portThe port of the PostgreSQL server to connect to.
optionsA set of
ConnectionOptionsto pass to the PostgreSQL server. -
Initialize an instance of PostgreSQLConnection.
Declaration
Swift
public convenience init(url: URL)Parameters
urlA URL of the following form: Postgres://userid:pwd@host:port/db.
-
Create a connection pool for PostgreSQLConnection’s.
Declaration
Swift
public static func createPool(url: URL, poolOptions: ConnectionPoolOptions) -> ConnectionPoolParameters
urlA URL of the PostgreSQL server of the following form: Postgres://userid:pwd@host:port/db.
poolOptionsA set of
ConnectionPoolOptionsto configure the created pool.Return Value
The
ConnectionPoolofPostgreSQLConnection. -
Create a connection pool for PostgreSQLConnection’s.
Declaration
Swift
public static func createPool(host: String, port: Int32, options: [ConnectionOptions]?, poolOptions: ConnectionPoolOptions) -> ConnectionPoolParameters
hostThe host of the PostgreSQL server to connect to.
portThe port of the PostgreSQL server to connect to.
optionsA set of
ConnectionOptionsto pass to the PostgreSQL server.poolOptionsA set of
ConnectionPoolOptionsto configure the created pool.Return Value
The
ConnectionPoolofPostgreSQLConnection. -
Return 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.
-
Establish a connection with the database.
Declaration
Swift
public func connect(onCompletion: @escaping (QueryResult) -> ())Parameters
onCompletionThe function to be called when the connection is established.
-
Establish a connection with the database.
Declaration
Swift
public func connectSync() -> QueryResultReturn Value
QueryError or nil if connection is succesful.
-
Close the connection to the database.
Declaration
Swift
public func closeConnection() -
Execute a query with parameters.
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.
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 raw query.
Declaration
Swift
public func execute(_ raw: String, onCompletion: @escaping ((QueryResult) -> ()))Parameters
rawA String with the raw query to execute.
onCompletionThe 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
rawA String with the raw 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 with parameters.
Declaration
Swift
public func execute(_ raw: String, parameters: [String : Any?], onCompletion: @escaping ((QueryResult) -> ()))Parameters
rawA String with the raw 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.
-
Prepare statement.
Declaration
Swift
public func prepareStatement(_ query: Query, onCompletion: @escaping ((QueryResult) -> ()))Parameters
queryThe query to prepare statement for.
onCompletionThe function to be called when the statement has been prepared.
-
Prepare statement.
Declaration
Swift
public func prepareStatement(_ raw: String, onCompletion: @escaping ((QueryResult) -> ()))Parameters
rawA String with the query to prepare statement for.
onCompletionThe function to be called when the statement has been prepared.
-
Execute a prepared statement.
Declaration
Swift
public func execute(preparedStatement: PreparedStatement, onCompletion: @escaping ((QueryResult) -> ()))Parameters
preparedStatementThe prepared statement to execute.
onCompletionThe 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
preparedStatementThe prepared statement to execute.
parametersAn array of the parameters.
onCompletionThe 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
preparedStatementThe prepared statement to execute.
parametersA dictionary of the parameters with parameter names as the keys.
onCompletionThe function to be called when the execution has completed.
-
Release a prepared statement.
Declaration
Swift
public func release(preparedStatement: PreparedStatement, onCompletion: @escaping ((QueryResult) -> ()))Parameters
preparedStatementThe prepared statement to release.
onCompletionThe function to be called when the execution has completed.
-
Start a transaction.
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.
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.
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.
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.
Declaration
Swift
public func rollback(to savepoint: String, onCompletion: @escaping ((QueryResult) -> ()))Parameters
onCompletionThe function to be called when the execution of rolback transaction command has completed.
-
Release a savepoint.
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
PostgreSQLConnection Class Reference