connect function

Future<Connection> connect(
  1. String uri, {
  2. Duration? connectionTimeout,
  3. String? applicationName,
  4. String? timeZone,
  5. TypeConverter? typeConverter,
  6. String? debugName,
})

Connect to a PostgreSQL database.

A uri has the following format:

'postgres://username:password@hostname:5432/database'

The application name is displayed in the pg_stat_activity view. This parameter is optional.

Care is required when setting the time zone, this is generally not required, the default, if omitted, is to use the server provided default which will typically be localtime or sometimes UTC. Setting the time zone to UTC will override the server provided default and all DateTime objects will be returned in UTC. In the case where the application server is on a different host than the database, and the host's DateTimes should be in the hosts localtime, then set this to the host's local time zone name. On linux systems this can be obtained using:

new File('/etc/timezone').readAsStringSync().trim()

The debug name is shown in error messages, this helps tracking down which connection caused an error.

The type converter allows the end user to provide their own mapping to and from Dart types to PostgreSQL types.

Implementation

Future<Connection> connect(
    String uri,
    { Duration? connectionTimeout,
      String? applicationName,
      String? timeZone,
      TypeConverter? typeConverter,
      String? debugName})

      => impl.ConnectionImpl.connect(
            uri,
            connectionTimeout: connectionTimeout,
            applicationName: applicationName,
            timeZone: timeZone,
            typeConverter: typeConverter,
            debugName: debugName);