serverpod_postgres_pool 2.1.1 copy "serverpod_postgres_pool: ^2.1.1" to clipboard
serverpod_postgres_pool: ^2.1.1 copied to clipboard

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'),
  );

  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();
}
1
likes
90
pub points
4%
popularity

Publisher

unverified uploader

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 serverpod_postgres_pool