postgres_pool 2.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 73

A library to control a maximized number of connections to a single PostgreSQL server.

Usage #

Once you've created the PgPool object, you can:

  • Use it as PostgreSQLExecutionContext (from package:postgres).
  • Use PgPool.run for non-transactional batches with optional retry.
  • Use PgPool.runTx for transactional batches with optional retry.

2.0.1 #

  • More efficient way to close the pool.

2.0.0 #

BREAKING CHANGES: refactor to match package:cockroachdb_pool's requirements.

  • Renamed or refactored:
    • PgCallbackFn -> PgSessionFn
    • PgUrl -> PgEndpoint
      • useSecure -> requireSsl
    • PgPool
      • Constructor parameters moved into PgPoolSettings, which allows tuning them while the pool is running.
      • info() -> status()
    • PgPoolInfo -> PgPoolStatus
      • available removed, use connections instead.
      • active -> activeSessionCount
      • waiting -> pendingSessionCount
  • Using package:retry.

1.1.0 #

  • Only one connection is opened at a time.
  • Randomized connection selection when multiple one is available. (Provides better distribution of queries, less overuse of single connection thread.)
  • Generated == and hashCode for PgUrl.
  • Removed leftover debug print.

1.0.0 #

  • Initial public release.

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();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  postgres_pool: ^2.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:postgres_pool/postgres_pool.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
46
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on Mar 30, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
executor ^2.0.0 2.2.1
meta ^1.0.0 1.1.8
postgres ^2.0.0 2.1.0
retry ^3.0.0 3.0.0+1
Transitive dependencies
buffer 1.0.6
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.4
path 1.6.4
stack_trace 1.9.3
typed_data 1.1.6
Dev dependencies
pedantic ^1.8.0
test ^1.6.0