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!
- ⚡️ Typesafe queries
- ⚡️ Custom models
- ⚡️ Minimal boilerplate
- ⚡️ Minimal code generation
- ⚡️ Supabase integration
@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,
);
}
@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),
],
);
}
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)]);
}
final authorsTable = AuthorsTable(supabaseClient);
final author = await authorsTable.fetchModel(
modelBuilder: Author.builder,
filter: AuthorsTable.name.equals('Michael Bond'),
);
print(author.books);
All the docs are over at typesafe-postgrest.