postgres 2.1.0

  • Readme
  • Changelog
  • Installing
  • 91

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.

Development branch #

The package's upcoming 2.0 version is being developed in the dev branch.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Changelog #

2.1.0 #

2.0.0 #

  • Fixed startup packet length when username is null (#111).
  • Finalized dev release.

2.0.0-dev1.0 #

  • Restricted field access on [PostgreSQLConnection].
  • Connection-level default query timeout.
  • Option to specify timeout for the transaction's "COMMIT" query.
  • Optimized byte buffer parsing and construction with package:buffer.
  • Hardened codebase with package:pedantic and additional lints.
  • Updated codebase to Dart 2.2.
  • PostgreSQLResult and PostgreSQLResultRow as the return value of a query.
    • Returned lists are protected with UnmodifiableListView.
    • Exposing column metadata through ColumnDescription.
    • row-level toTableColumnMap and toColumnMap
  • PostgreSQLConnection and _TransactionProxy share the OID cache.
  • default value for query(allowReuse = true) is set only in the implementation method.

Breaking behaviour

  • Table OIDs are always resolved to table names (and not only with mapped queries).

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: ^2.1.0

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]
86
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
91
Learn more about scoring.

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

  • Dart: 2.7.0
  • pana: 0.13.1+4

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.

Dependencies

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