GitHub - supabase/postgrest-dart: Dart client for PostgREST (original) (raw)

Postgrest Dart

WarningThis repository has been moved to the supabase-flutter repo.

Dart client for PostgREST. The goal of this library is to make an "ORM-like" restful interface.

Using

The usage should be the same as postgrest-js except:

You can find detail documentation from here.

Reading your data

import 'package:postgrest/postgrest.dart';

final url = 'https://example.com/postgrest/endpoint'; final client = PostgrestClient(url); final response = await client.from('users').select();

Reading your data and converting it to an object

import 'package:postgrest/postgrest.dart';

final url = 'https://example.com/postgrest/endpoint'; final client = PostgrestClient(url); final response = await client .from('users') .select() .withConverter((data) => data.map(User.fromJson).toList());

Insert records

import 'package:postgrest/postgrest.dart';

final url = 'https://example.com/postgrest/endpoint'; final client = PostgrestClient(url); try { await client.from('users') .insert([ {'username': 'supabot', 'status': 'ONLINE'} ]); } on PostgrestException catch (error, stacktrace) { // handle a PostgrestError print('$error \n $stacktrace'); } catch (error, stacktrace) { // handle other errors print('$error \n $stracktrace'); }

Update a record

import 'package:postgrest/postgrest.dart';

final url = 'https://example.com/postgrest/endpoint'; final client = PostgrestClient(url); await client.from('users') .update({'status': 'OFFLINE'}) .eq('username', 'dragarcia');

Delete records

import 'package:postgrest/postgrest.dart';

final url = 'https://example.com/postgrest/endpoint'; final client = PostgrestClient(url); await client.from('users') .delete() .eq('username', 'supabot');

Get Count

import 'package:postgrest/postgrest.dart';

final url = 'https://example.com/postgrest/endpoint'; final client = PostgrestClient(url); final response = await client.from('countries') .select('*', FetchOptions(count: CountOption.exact)); final data = response.data; final count = response.count;

Contributing

License

This repo is licensed under MIT.

Credits