drift/extras/drift_postgres
David Martos 039838b2ba
Support bytea sql literal in postgres (#2943)
2024-04-06 14:37:28 +02:00
..
example Fix generating variables with custom types 2023-12-10 14:23:19 +01:00
lib Improve check for if postgres session is still open (#2928) 2024-03-22 19:43:09 +01:00
test Support bytea sql literal in postgres (#2943) 2024-04-06 14:37:28 +02:00
.gitignore PostgreSQL support (#1507) 2021-11-11 14:40:41 +01:00
CHANGELOG.md Provide comparable expressions for pg time values 2024-02-10 00:33:04 +01:00
LICENSE Prepare to publish drift postgres 2023-10-20 12:04:14 +02:00
README.md Add recommended build options for drift postgres 2024-02-25 00:06:12 +01:00
analysis_options.yaml Fix lints and warnings added in Dart 3.0 2023-05-12 22:42:21 +02:00
build.yaml Add recommended build options for drift postgres 2024-02-25 00:06:12 +01:00
pubspec.yaml Prepare release 2024-02-24 23:17:54 +01:00

README.md

package:drift_postgres extends drift to support talking to PostgreSQL databases by using the postgres package.

Using this

For general notes on using drift, see this guide. Detailed docs on getting started with drift_postgres are available here.

To use drift_postgres, add this to your pubspec.yaml

dependencies:
  drift: "$latest version"
  drift_postgres: ^0.1.0

To connect your drift database class to postgres, use a PgDatabase from package:drift_postgres/postgres.dart:

final database = AppDatabase(PgDatabase(
  endpoint: PgEndpoint(
    host: 'localhost',
    database: 'postgres',
    username: 'postgres',
    password: 'postgres',
  ),
));

Also, consider adding builder options to make drift generate postgres-specific code:

# build.yaml
targets:
  $default:
    builders:
      drift_dev:
        options:
          sql:
            dialects:
              - sqlite # remove this line if you only need postgres
              - postgres

Running tests

To test this package, first run

docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres postgres

It can then be tested with dart test -j 1 (concurrency needs to be disabled since tests are using the same database).