postgres_pool 2.1.6+1 copy "postgres_pool: ^2.1.6+1" to clipboard
postgres_pool: ^2.1.6+1 copied to clipboard

discontinuedreplaced by: postgres

Postgresql connection pool with a wide range of automated reconnect parameters.

example/example.dart

import 'package:postgres_pool/postgres_pool.dart';

Future<void> main() async {
  final pg = PgPool(
    PgEndpoint(
      host: 'localhost',
      port: 5432,
      database: 'test',
      username: 'test',
      password: 'test',
    ),
    settings: PgPoolSettings()
      ..maxConnectionAge = Duration(hours: 1)
      ..concurrency = 4,
  );

  final futures = <Future>[];
  for (var i = 0; i < 100; i++) {
    // pg.run schedules a callback function to be called when a connection
    // becomes available. We are not blocking on the result yet.
    final f = pg.run((c) async {
      final rs = await c.query(
        'SELECT COUNT(*) FROM test_table WHERE type = @type',
        substitutionValues: {
          'type': i,
        },
      );
      return rs[0][0];
    });

    futures.add(f);
  }

  // We've scheduled 100 connection-using callbacks, and very likely the first
  // one is already ongoing. Let's wait for all of them.
  await Future.wait(futures);

  await pg.close();
}
20
likes
150
pub points
81%
popularity

Publisher

verified publisheragilord.com

Postgresql connection pool with a wide range of automated reconnect parameters.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

executor, postgres, retry

More

Packages that depend on postgres_pool