Retrieves a connection to the database this instance connects to.
If no connection exists, one will be created. A store will have no more than one connection at a time. You should rarely need to access this connection directly.
Source
Future<PostgreSQLConnection> getDatabaseConnection() async {
if (_databaseConnection == null || _databaseConnection.isClosed) {
if (connectFunction == null) {
throw new QueryException(QueryExceptionEvent.internalFailure,
message: "Could not connect to database, no connect function.");
}
if (_pendingConnectionCompleter == null) {
_pendingConnectionCompleter = new Completer<PostgreSQLConnection>();
connectFunction().timeout(connectTimeout).then((conn) {
_databaseConnection = conn;
_pendingConnectionCompleter.complete(_databaseConnection);
_pendingConnectionCompleter = null;
}).catchError((e) {
_pendingConnectionCompleter.completeError(new QueryException(
QueryExceptionEvent.connectionFailure,
underlyingException: e));
_pendingConnectionCompleter = null;
});
}
return _pendingConnectionCompleter.future;
}
return _databaseConnection;
}