Connection
public final class ConnectionRepresents a connection to a PostgreSQL server
- 
                  
                  designated initializer. DeclarationSwift public init(connectInfo: ConnectInfo)ParametersconnectInfothe arguments that will be used to open a connection 
- 
                  
                  Initializes with a fixed set of connection parameters DeclarationSwift public convenience init(host: String = "localhost", port: String = "5432", user: String, password: String = "", dbname: String, sslMode: ConnectParam.SSLMode = .prefer)Parametershostthe host to connect to. Defaults to localhost portThe port to connect to, as a string. Defaults to 5432 userthe user to connect as passwordthe password for user. Defauls to an empty string dbnamethe name of the ddatabase to connect to sslModethe SSL Mode to use. Defaults to .prefer 
- 
                  
                  Creates a connection using the same parameters as the specified connection DeclarationSwift public convenience init(cloning: Connection)ParameterscloningThe connection to clone 
- 
                  
                  opens the connection to the database server DeclarationSwift public func open() throws
- 
                  
                  closes the connection to the database server DeclarationSwift public func close()
- 
                  
                  the currently reported last error message from the server DeclarationSwift public var lastErrorMessage: String { get }
- 
                  
                  true if the connection is currently open DeclarationSwift public var isConnected: Bool { get }
- 
                  
                  Returns the version of the server. Only works if a connection is open. DeclarationSwift public func serverVersion() throws -> StringReturn Valuethe server version string 
- 
                  
                  Wraps a closure in a transaction. If an error is thrown, performs a rollback. Otherwise, performs a commit. Throws any errors executing the queryDeclarationSwift public func withTransaction<T>(body: (Connection) throws -> T?) throws -> T?Parametersbodyclosure to execute. Passed the connection to use Return Valuethe value returned from the body closure 
- 
                  
                  Executes the query and returns the results Throws if connection isn’t open, or don’t get a valid responseDeclarationSwift @discardableResult public func execute(query: String) throws -> PGResultParametersqueryquery to perform Return Valuethe results of that query 
- 
                  
                  Execute a query with parameters Throws if connection not open, don’t get a valid response, query parameter mismatchDeclarationSwift @discardableResult public func execute(query: String, parameters: [QueryParameter?]) throws -> PGResultParametersquerythe query string with placeholders ($1,$2, etc.) for each parameter parametersarray of QueryParameters Return Valuethe results of the query 
- 
                  
                  Execute the query and returns the results. Internally transfers data in binary format Throws if connection isn’t open, or don’t get a valid responseDeclarationSwift @discardableResult public func executeBinary(query: String) throws -> PGResultParametersqueryquery to perform Return Valuethe results of that query 
- 
                  
                  Returns the value of row 0, column 0 of a query that returns 1 row and 1 column Throws if the data types don’t match, or an error executing queryDeclarationSwift public func getSingleRowValue<T>(query: String) throws -> T?Parametersquerya query that should return 1 row with 1 column Return Valuethe value 
- 
                  
                  Creates a dispatch read source for this connection that will call callbackonqueuewhen a notification is receivedThrows if fails to get the socket for the connectionDeclarationSwift public func listen(toChannel channel: String, queue: DispatchQueue, callback: @escaping (_ notification: PGNotification?, _ error: Error?) -> Void) throws -> DispatchSourceReadParameterschannelthe channel to register for queuethe queue to create the DispatchSource on callbackthe callback notificationThe notification received from the database errorAny error while reading the notification. If not nil, the source will have been canceled Return Valuethe dispatch socket to activate 
 View on GitHub
View on GitHub Connection Class Reference
        Connection Class Reference