Skip to main content

postgrest 3.0.0-dev.14 copy "postgrest: ^3.0.0-dev.14" to clipboard
postgrest: ^3.0.0-dev.14 copied to clipboard

PostgREST client for Dart. This library provides an ORM interface to PostgREST.


Supabase Logo

postgrest

Dart client library for PostgREST, providing an ORM-like interface to the Supabase database.

Guides · Reference Docs

pub package pub test

postgrest is the database client of the Supabase Dart and Flutter SDKs. In an app, use it through supabase_flutter or supabase, whose clients expose it as supabase.table(…), supabase.from(…) and supabase.rpc. Depend on postgrest directly only to talk to a PostgREST server without the rest of Supabase.

Usage #

Queries are typed by a Dart file that supabase_typegen generates from the database schema, with a row type per table (BooksRow), the insert and update values that writes accept (BooksInsert, BooksUpdate), and a class holding the table definition and one constant per column (Books):

dart pub add dev:supabase_typegen
supabase gen types --lang dart --local > lib/supabase_schema.g.dart

Import the generated supabase_schema.g.dart and pass the table definition to table(). Filters are methods on the column constants, so the compiler checks every column name and value:

import 'package:my_app/supabase_schema.g.dart';
import 'package:postgrest/postgrest.dart';

Future<void> main() async {
  final client = PostgrestClient(
    'https://your-project.supabase.co/rest/v1',
    headers: {'apikey': 'your-publishable-key'},
  );

  final List<BooksRow> books = await client
      .table(Books.table)
      .select()
      .where(Books.inPrint.isTrue() & Books.price.lt(10))
      .order(Books.title)
      .limit(20);

  await client
      .table(Books.table)
      .insert(BooksInsert(authorId: 2, title: 'Dune'));

  // A typed update() or delete() sends nothing until where() or all().
  await client
      .table(Books.table)
      .update(BooksUpdate(inPrint: false))
      .where(Books.id.eq(1));

  final BooksRow? book = await client.rpc.bookById(bookId: 1);
}

from('books') with Map<String, dynamic> rows and rpc('fn', params: {…}) remain as the untyped fallback for tables and functions that are not in the generated file.

Docs #

The docs can be found on the official Supabase website.

License #

This repo is licensed under MIT.

Credits #

137
likes
0
points
1.26M
downloads

Documentation

Documentation

Publisher

verified publishersupabase.io

Weekly Downloads

PostgREST client for Dart. This library provides an ORM interface to PostgREST.

Homepage
Repository (GitHub)
View/report issues

Topics

#supabase #postgrest #database #orm #api

License

unknown (license)

Dependencies

crypto, http, logging, meta, supabase_common, yet_another_json_isolate

More

Packages that depend on postgrest