raindrop_postgres 0.1.1 copy "raindrop_postgres: ^0.1.1" to clipboard
raindrop_postgres: ^0.1.1 copied to clipboard

The Postgres driver for raindrop, built on top of the postgres package.

💧 raindrop_postgres

Pub ci coverage style: very good analysis License: MIT


The Postgres driver for raindrop, built on postgres.

Usage #

Declare tables with postgresTable, then hand a PostgresDelegate an open Connection (or a Pool):

import 'package:postgres/postgres.dart';
import 'package:raindrop/raindrop.dart';
import 'package:raindrop_postgres/raindrop_postgres.dart';

final users = postgresTable('users', UserSchema.new);

void main() async {
  final connection = await Connection.open(
    Endpoint(host: 'localhost', database: 'postgres', username: 'postgres'),
  );
  final db = Raindrop(PostgresDelegate(connection));

  final [user] = await db.insert(into: users).values([
    const User(name: 'Alex'),
  ]).returning();
}

The connection is yours: the driver does not pool, retry, or reconnect.

Beyond the core DSL #

Everything in the core raindrop DSL works unchanged. On top of it this driver adds upserts:

await db.insert(into: users).values([user])
    .onConflict([users.email])
    .doUpdate([users.age.to(excluded(users.age))]);
// INSERT ... ON CONFLICT ("email") DO UPDATE SET "age" = "excluded"."age"
  • returning() on inserts, updates and deletes yields the affected rows.
  • now() and genRandomUuid() evaluate in the database.
  • Column types beyond the core set: boolean, dateTime (TIMESTAMP), bigInt (NUMERIC), textArray (TEXT[]) and blob (BYTEA).
  • % works on bigInt columns, computed over NUMERIC.
1
likes
160
points
173
downloads

Documentation

API reference

Publisher

verified publisherwolfenrain.dev

Weekly Downloads

The Postgres driver for raindrop, built on top of the postgres package.

Repository (GitHub)
View/report issues
Contributing

Topics

#sql #database #postgres #migrations

License

MIT (license)

Dependencies

postgres, raindrop

More

Packages that depend on raindrop_postgres