PostgreSQLPool class

Pool de conexões PostgreSQLConnection.

As conexões são criadas por connectionFactory (com todas as opções de PostgreSQLConnection) e abertas sob demanda, até PostgreSQLPoolSettings.maxConnectionCount. Cada sessão (run, runTx, withConnection ou um dos métodos de PostgreSQLExecutionContext) usa uma conexão com exclusividade e a devolve ao terminar; quem chega quando todas estão em uso espera, em ordem de chegada.

Uma conexão é fechada em vez de voltar ao pool quando: foi fechada (por exemplo, pelo servidor); a sessão falhou com TimeoutException (a consulta pode continuar rodando no servidor); a sessão deixou uma transação aberta (um BEGIN sem COMMIT/ROLLBACK); ou atingiu um dos limites de PostgreSQLPoolSettings. Erros de SQL comuns (por exemplo, violação de unicidade) não fecham a conexão.

Configurações de sessão alteradas com SET continuam valendo para as próximas sessões da mesma conexão; prefira os parâmetros de startup da conexão ou PostgreSQLPoolSettings.onOpen.

Implemented types
Available extensions

Constructors

PostgreSQLPool(PostgreSQLConnection connectionFactory(), {PostgreSQLPoolSettings settings = const PostgreSQLPoolSettings()})

Properties

hashCode → int
The hash code for this object.
no setterinherited
isClosed → bool
Se close já foi chamado.
no setter
queueSize → int
Sessões esperando uma conexão.
no setteroverride
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
settings → PostgreSQLPoolSettings
final
status → PoolStatus
Estado atual do pool.
no setter

Methods

cancelTransaction({String? reason}) → void
Não faz nada: o pool não é uma transação. Use runTx.
override
close({bool force = false}) → Future<void>
Fecha o pool. Ver PoolCore.close.
copyFrom(String sql, Stream<List<int>> data, {dynamic substitutionValues, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign, int? timeoutInSeconds}) → Future<int>
PostgreSQLConnection.copyFrom com uma conexão do pool.
copyFrom(String sql, Stream<List<int>> data, {dynamic substitutionValues, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign, int? timeoutInSeconds}) → Future<int>

Available on PostgreSQLExecutionContext, provided by the PgCopyExecutionContext extension

copyRows(String table, List<String> columns, Iterable<List<Object?>> rows, {String? schema, int? timeoutInSeconds}) → Future<int>
PostgreSQLConnection.copyRows com uma conexão do pool.
copyRows(String table, List<String> columns, Iterable<List<Object?>> rows, {String? schema, int? timeoutInSeconds}) → Future<int>

Available on PostgreSQLExecutionContext, provided by the PgCopyExecutionContext extension

copyTo(String sql, void onData(Uint8List data), {dynamic substitutionValues, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign, int? timeoutInSeconds}) → Future<int>
PostgreSQLConnection.copyTo com uma conexão do pool.
copyTo(String sql, void onData(Uint8List data), {dynamic substitutionValues, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign, int? timeoutInSeconds}) → Future<int>

Available on PostgreSQLExecutionContext, provided by the PgCopyExecutionContext extension

execute(String fmtString, {dynamic substitutionValues = const <String, dynamic>{}, int? timeoutInSeconds, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign}) → Future<int>
Executes a query on this context.
override
mappedResultsQuery(String fmtString, {dynamic substitutionValues = const <String, dynamic>{}, bool? allowReuse, int? timeoutInSeconds, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign}) → Future<List<Map<String, Map<String, dynamic>>>>
Executes a query on this connection and returns each row as a Map.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
query(String fmtString, {dynamic substitutionValues, bool? allowReuse, int? timeoutInSeconds, bool? useSimpleQueryProtocol, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign}) → Future<PostgreSQLResult>
Executes a query on this context.
override
queryAsMap(String fmtString, {dynamic substitutionValues = const <String, dynamic>{}, bool? allowReuse, int? timeoutInSeconds, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign}) → Future<List<Map<String, dynamic>>>
Executes a query on this connection and returns each row as a Map.
override
queryStream(String fmtString, {dynamic substitutionValues, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign, int fetchSize = 1000, int? timeoutInSeconds}) → Stream<PostgreSQLResultRow>
PostgreSQLConnection.queryStream com uma conexão do pool, que fica ocupada até o stream terminar ou ser cancelado.
queryStream(String fmtString, {dynamic substitutionValues, PlaceholderIdentifier placeholderIdentifier = PlaceholderIdentifier.atSign, int fetchSize = 1000, int? timeoutInSeconds}) → Stream<PostgreSQLResultRow>

Available on PostgreSQLExecutionContext, provided by the PgQueryStreamExecutionContext extension

run<R>(Future<R> fn(PostgreSQLExecutionContext ctx), {PgRetryOptions? retryOptions}) → Future<R>
Executa fn fora de transação, com uma conexão exclusiva (ver withConnection).
runTx<R>(Future<R> fn(PostgreSQLExecutionContext ctx), {PgRetryOptions? retryOptions, int? commitTimeoutInSeconds}) → Future<R>
Executa fn numa transação (PostgreSQLConnection.transaction). Com retryOptions, a transação inteira é repetida (com outra conexão) quando falha com um erro aceito por PgRetryOptions.retryIf (por padrão, falha de serialização e deadlock).
savepoint<T>(Future<T> block(PostgreSQLExecutionContext ctx)) → Future<T>

Available on PostgreSQLExecutionContext, provided by the PgSavepointExecutionContext extension

Executa block dentro de um SAVEPOINT da transação atual.
toString() → String
A string representation of this object.
inherited
withConnection<R>(Future<R> fn(PostgreSQLConnection connection), {PgRetryOptions? retryOptions}) → Future<R>
Executa fn com uma conexão exclusiva do pool.

Operators

operator ==(Object other) → bool
The equality operator.
inherited