typesafe_supabase 0.0.4 copy "typesafe_supabase: ^0.0.4" to clipboard
typesafe_supabase: ^0.0.4 copied to clipboard

A dart package that enables type-safe queries to a Supabase database.

typesafe-supabase #

An extension of typesafe-postgrest for Supabase databases. It minimizes setup and provides additional Supabase-specific features.

🚨 This is NOT an official supabase package and NOT developed by the Supabase team!

✨ Features #

  • ✅ ⚡️ Typesafe queries
  • ✅ ⚡️ Custom models
  • ✅ ⚡️ Minimal boilerplate
  • ✅ ⚡️ Minimal code generation
  • ✅ ⚡️ Supabase integration

😉 Sneak peek #

Define your tables #

@PgTableHere()
class AuthorsTable extends SupabaseTable<AuthorsTable> {
  AuthorsTable(super.client) : super(tableName: tableName, primaryKey: [id]);

  static const tableName = PgTableName<AuthorsTable>('authors');

  @PgColumnHasDefault()
  static final id = PgBigIntColumn<AuthorsTable>('id');

  static final name = PgStringColumn<AuthorsTable>('name');

  static final books = PgJoinToMany<AuthorsTable, BooksTable>(
    joinColumn: id,
    joinedTableName: BooksTable.tableName,
  );
}

Define your models #

@PgModelHere()
class Author extends PgModel<AuthorsTable> {
  Author(super.json) : super(builder: builder);

  static final builder = PgModelBuilder<AuthorsTable, Author>(
    constructor: Author.new,
    columns: [
      AuthorsTable.id,
      AuthorsTable.name,
      AuthorsTable.books(AuthorBook.builder),
    ],
  );
}

Generate a tiny piece of code #

dart run build_runner build
(Toggle to view the generated code)
extension PgAuthorX on Author {
  BigInt get id => value(AuthorsTable.id);
  String get name => value(AuthorsTable.name);
  List<AuthorBook> get books => value(AuthorsTable.books(AuthorBook.builder));
}
typedef AuthorsTableInsert = AuthorsTableUpsert;

class AuthorsTableUpsert extends PgUpsert<AuthorsTable> {
  AuthorsTableUpsert({required String name, BigInt? id})
    : super([AuthorsTable.name(name), if (id != null) AuthorsTable.id(id)]);
}

Use it! #

final authorsTable = AuthorsTable(supabaseClient);

final author = await authorsTable.fetchModel(
  modelBuilder: Author.builder,
  filter: AuthorsTable.name.equals('Michael Bond'),
);

print(author.books);

📝 Documentation #

All the docs are over at typesafe-postgrest.

2
likes
150
points
219
downloads

Publisher

verified publisherjakesmd.dev

Weekly Downloads

A dart package that enables type-safe queries to a Supabase database.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

meta, supabase, typesafe_postgrest

More

Packages that depend on typesafe_supabase