supabase_extensions is a couple of extensions to the Supabase API
- Using SQL statement strings to get results from Supabase (uses PostgREST behind the scenes)
- Shorter syntax when possible
- Simpler way to listen to changes in the Database
Note: only Select/Insert SQL statement are supported (WIP)
For using it on your app:
import 'package:supabase_extensions/base.dart';
For API reference check here
Fetching data using raw queries' strings using Supabase's database (Postgres)
// init Supabase Client..
// final supabase = SupabaseClient('supabaseUrl', 'supabaseKey');
const sqlString = 'SELECT code FROM courses WHERE code > 32000 ORDER BY code LIMIT 2';
QueryResults queryResults = await supabase.sql(sqlString);
List<Map<String, dynamic>> rows = queryResults.rows;
Get the user's ID (if exist) easily
// init Supabase Client..
// final supabase = SupabaseClient('supabaseUrl', 'supabaseKey');
String? userId = supabase.uid; /// instead supabase.auth.currentUser?.id
Get if the user already logged in or not
// init Supabase Client..
// final supabase = SupabaseClient('supabaseUrl', 'supabaseKey');
bool isLoggedIn = supabase.isLogged; /// instead supabase.auth.currentUser?.id != null
Get the user's current session access token (if the user already logged in)
// init Supabase Client..
// final supabase = SupabaseClient('supabaseUrl', 'supabaseKey');
String? accessToken = supabase.jwt; /// instead supabase.auth.currentSession?.accessToken
// init Supabase Client..
// final supabase = SupabaseClient('supabaseUrl', 'supabaseKey');
// Regular way
supabase.from('test').stream(primaryKey: ['id']).listen((event) {
print(event);
});
You can listen to only single event type ('INSERT'
,'UPDATE'
or 'DELETE'
)
// any event in table 'test'
supabase.on('table').listen((event) {
print(event);
});
// only INSERT events in table 'test'
supabase.on('table', CrudEvent.insert).listen((event) {
print(event);
});
// shorter syntax for only INSERT, DELETE
supabase.onInsert('table').listen((event) {
print(event);
});
supabase.onDelete('table').listen((event) {
print(event);
});
!! Remember to remove the channels and to close streams when you're done
supabase.removeAllChannels();
supabase.closeAllStreams(); // ADD THIS TOO!
Return the name of the provider the user is logged to ('apple', 'google'..)
String? providerName = supabase.auth.provider; /// instead supabase.auth.provider
Based heavily on the Postgrest API