postgres_pool 1.0.0 copy "postgres_pool: ^1.0.0" to clipboard
postgres_pool: ^1.0.0 copied to clipboard

discontinuedreplaced by: postgres
outdated

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(
    PgUrl(
        host: 'localhost',
        port: 5432,
        database: 'test',
        username: 'test',
        password: 'test'),
  );

  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
0
pub points
81%
popularity

Publisher

verified publisheragilord.com

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

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

executor, postgres

More

Packages that depend on postgres_pool