drift_postgres 0.1.0 copy "drift_postgres: ^0.1.0" to clipboard
drift_postgres: ^0.1.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_v3_experimental.dart';
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()();
}

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

  @override
  int get schemaVersion => 1;
}

void main() async {
  final database = DriftPostgresDatabase(PgDatabase(
    endpoint: PgEndpoint(
      host: 'localhost',
      database: 'postgres',
      username: 'postgres',
      password: 'postgres',
    ),
    logStatements: true,
  ));

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

  await database.close();
}
14
likes
120
pub points
86%
popularity

Publisher

verified publishersimonbinder.eu

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