drift_postgres 1.3.0 copy "drift_postgres: ^1.3.0" to clipboard
drift_postgres: ^1.3.0 copied to clipboard

Postgres implementation and APIs for the drift database package.

example/main.dart

import 'package:drift/drift.dart';
import 'package:drift_postgres/drift_postgres.dart';
import 'package:postgres/postgres.dart' as pg;
import 'package:uuid/uuid.dart';

part 'main.g.dart';

class Users extends Table {
  UuidColumn get id => customType(PgTypes.uuid).withDefault(genRandomUuid())();
  TextColumn get name => text()();

  @override
  Set<Column<Object>>? get primaryKey => {id};
}

@DriftDatabase(tables: [Users])
class DriftPostgresDatabase extends _$DriftPostgresDatabase {
  DriftPostgresDatabase(super.e);

  @override
  int get schemaVersion => 1;
}

void main() async {
  final database = DriftPostgresDatabase(PgDatabase(
    endpoint: pg.Endpoint(
      host: 'localhost',
      database: 'postgres',
      username: 'postgres',
      password: 'postgres',
    ),
    settings: pg.ConnectionSettings(
      // If you expect to talk to a Postgres database over a public connection,
      // please use SslMode.verifyFull instead.
      sslMode: pg.SslMode.disable,
    ),
    logStatements: true,
  ));

  final user = await database.users.insertReturning(
      UsersCompanion.insert(name: 'Simon', id: Value(Uuid().v4obj())));
  print(user);

  await database.users.deleteOne(user);

  await database.close();
}
18
likes
140
points
1.01k
downloads

Publisher

verified publishersimonbinder.eu

Weekly Downloads

Postgres implementation and APIs for the drift database package.

Homepage
Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

MIT (license)

Dependencies

collection, drift, meta, postgres, uuid

More

Packages that depend on drift_postgres