-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connection management? #16
Comments
Here is a proposed API for connection pooling: ( public class ConnectionPool {
private let pool: Pool<Connection>
public init(initialCapacity: Int, maxCapacity: Int = 0, timeout: Int = 0, connectionGenerator: @escaping () -> Connection?, connectionReleaser: @escaping (Connection) -> ()) { }
deinit { disconnect() }
public func getConnection() -> Connection? {}
func release(connection: Connection) { }
public func disconnect() {}
} The plugins will create an instance of ConnectionPool with database specific connection generators and releasers. getConnection() will return a ConnectionPoolConnection - a wrapper around the actual connection. The main purpose of this is to automatically release connection using ConnectionPoolConnection.deinit: public class ConnectionPoolConnection: Connection {
private var connection: Connection?
private weak var pool: ConnectionPool?
init(connection: Connection, pool: ConnectionPool) { }
deinit {
if let connection = connection {
pool?.release(connection: connection)
}
}
public func connect(onCompletion: (QueryError?) -> ()) { }
public func closeConnection() {
if let connection = connection {
pool?.release(connection: connection)
self.connection = nil
}
}
public var isConnected: Bool {
return connection != nil
}
public func execute(query: Query, onCompletion: @escaping ((QueryResult) -> ())) {
connection?.execute(query: query, onCompletion: onCompletion)
}
// Other Connection functions.
} We have to decide what to do if the connection is released and e.g. connection.execute() is called. I'll open a separate issue to discuss this. |
Right now I have for each Kitura handler, creating a new PostgreSQL connection, connecting to it, then servicing the request. I would like to perhaps use a single connection object that can do a reconnect only if needed (in case the connection has been lost for some reason). Do do that, I need connection status. Perhaps the result of running:
https://www.postgresql.org/docs/9.1/static/libpq-status.html
Do we have plans for these find of connection management policies?
The text was updated successfully, but these errors were encountered: