postgres 1.0.2

  • Readme
  • Changelog
  • Installing
  • 83

postgres #

Build Status codecov

A library for connecting to and querying PostgreSQL databases.

This driver uses the more efficient and secure extended query format of the PostgreSQL protocol.

Usage #

Create PostgreSQLConnections and open them:

var connection = new PostgreSQLConnection("localhost", 5432, "dart_test", username: "dart", password: "dart");
await connection.open();

Execute queries with query:

List<List<dynamic>> results = await connection.query("SELECT a, b FROM table WHERE a = @aValue", substitutionValues: {
    "aValue" : 3
});

for (final row in results) {
  var a = row[0];
  var b = row[1];

} 

Return rows as maps containing table and column names:

List<Map<String, Map<String, dynamic>>> results = await connection.mappedResultsQuery(
  "SELECT t.id, t.name, u.name FROM t LEFT OUTER JOIN u ON t.id=u.t_id");

for (final row in results) {
  var tID = row["t"]["id"];
  var tName = row["t"]["name"];
  var uName = row["u"]["name"];
}

Execute queries in a transaction:

await connection.transaction((ctx) async {
    var result = await ctx.query("SELECT id FROM table");
    await ctx.query("INSERT INTO table (id) VALUES (@a:int4)", {
        "a" : result.last[0] + 1
    });
});

See the API documentation: https://www.dartdocs.org/documentation/postgres/latest.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Changelog #

1.0.2 #

  • Add connection queue size

1.0.1 #

  • Prevent the table name resolution of OIDs <= 0.

1.0.0 #

  • Adds support for Dart 2

0.9.9 #

  • Add full support for UUID columns.

0.9.8 #

  • Preserve error stacktrace on various query or transaction errors.
  • Read support for BYTEA columns.

0.9.7 #

  • Adds Connection.mappedResultsQuery to return query results as a Map with keys for table and column names.

0.9.6 #

  • Adds Connection.notifications to listen for NOTIFY events (thanks @andrewst)
  • Adds better error reporting.
  • Adds support for JSONB columns.
  • Fixes issue when encoding UTF16 characters (thanks @andrewst)

0.9.5 #

  • Allow connect via SSL.

0.9.4 #

  • Fixed issue with buffer length

0.9.3 #

  • Fixed issue with UTF8 encoding

0.9.2 #

  • Bump for documentation

0.9.1 #

  • Added transactions: PostgreSQLConnection.transaction and PostgreSQLConnection.cancelTransaction.

0.9.0 #

  • Initial version

Use this package as a library

1. Depend on it

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


dependencies:
  postgres: ^1.0.2

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/postgres.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
84
Health:
Code health derived from static analysis. [more]
77
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
89
Overall:
Weighted score of the above. [more]
83
Learn more about scoring.

We analyzed this package on Oct 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:postgres/postgres.dart with components: io.

Health suggestions

Fix lib/src/connection.dart. (-11.78 points)

Analysis of lib/src/connection.dart reported 25 hints, including:

line 38 col 8: Don't explicitly initialize variables to null.

line 38 col 21: Use = to separate a named parameter from its default value.

line 38 col 29: Don't explicitly initialize variables to null.

line 38 col 42: Use = to separate a named parameter from its default value.

line 38 col 71: Use = to separate a named parameter from its default value.

Fix lib/src/execution_context.dart. (-4.89 points)

Analysis of lib/src/execution_context.dart reported 10 hints, including:

line 32 col 6: Don't explicitly initialize variables to null.

line 32 col 45: Use = to separate a named parameter from its default value.

line 32 col 68: Use = to separate a named parameter from its default value.

line 41 col 42: Don't explicitly initialize variables to null.

line 41 col 81: Use = to separate a named parameter from its default value.

Fix lib/src/substituter.dart. (-2.48 points)

Analysis of lib/src/substituter.dart reported 5 hints:

line 8 col 34: Don't explicitly initialize variables to null.

line 8 col 57: Use = to separate a named parameter from its default value.

line 56 col 8: Don't explicitly initialize variables to null.

line 56 col 44: Use = to separate a named parameter from its default value.

line 62 col 27: Don't explicitly initialize variables to null.

Fix additional 11 files with analysis or formatting issues. (-5.98 points)

Additional issues in the following files:

  • lib/src/client_messages.dart (4 hints)
  • lib/src/query.dart (3 hints)
  • lib/src/transaction_proxy.dart (2 hints)
  • lib/src/connection_fsm.dart (1 hint)
  • lib/src/exceptions.dart (1 hint)
  • lib/src/text_codec.dart (1 hint)
  • lib/src/binary_codec.dart (Run dartfmt to format lib/src/binary_codec.dart.)
  • lib/src/query_cache.dart (Run dartfmt to format lib/src/query_cache.dart.)
  • lib/src/query_queue.dart (Run dartfmt to format lib/src/query_queue.dart.)
  • lib/src/server_messages.dart (Run dartfmt to format lib/src/server_messages.dart.)
  • lib/src/types.dart (Run dartfmt to format lib/src/types.dart.)

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and postgres.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Package is getting outdated. (-0.55 points)

The package was last published 52 weeks ago.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
crypto ^2.0.0 2.1.3
Transitive dependencies
charcode 1.1.2
collection 1.14.12
convert 2.1.1
typed_data 1.1.6
Dev dependencies
coverage any
test ^1.3.0