pasubot 0.0.1
pasubot: ^0.0.1 copied to clipboard
A dart client for Pasubot. This client makes it simple for developers to build secure and scalable products.
example/main.dart
import 'dart:async';
import 'dart:io';
import 'package:pasubot/pasubot.dart';
Future<void> main() async {
const pasubotUrl = 'YOUR_PASUBOT_URL';
const pasubotKey = 'YOUR_ANON_KEY';
final pasubot = PasubotClient(pasubotUrl, pasubotKey);
// query data
final data =
await pasubot.from('countries').select().order('name', ascending: true);
print(data);
// insert data
await pasubot.from('countries').insert([
{'name': 'Singapore'},
]);
// update data
await pasubot.from('countries').update({'name': 'Singapore'}).eq('id', 1);
// delete data
await pasubot.from('countries').delete().eq('id', 1);
// realtime
final realtimeChannel = pasubot.channel('my_channel');
realtimeChannel
.onPostgresChanges(
event: PostgresChangeEvent.all,
schema: 'public',
table: 'countries',
callback: (payload) {})
.subscribe();
// remember to remove channel when no longer needed
pasubot.removeChannel(realtimeChannel);
// stream
final streamSubscription = pasubot
.from('countries')
.stream(primaryKey: ['id'])
.order('name')
.limit(10)
.listen((snapshot) {
print('snapshot: $snapshot');
});
// remember to remove subscription
streamSubscription.cancel();
// Upload file to bucket "public"
final file = File('example.txt');
file.writeAsStringSync('File content');
final storageResponse =
await pasubot.storage.from('public').upload('example.txt', file);
print('upload response : $storageResponse');
// Get download url
final urlResponse =
await pasubot.storage.from('public').createSignedUrl('example.txt', 60);
print('download url : $urlResponse');
// Download text file
final fileResponse =
await pasubot.storage.from('public').download('example.txt');
print('downloaded file : ${String.fromCharCodes(fileResponse)}');
// Delete file
final deleteFileResponse =
await pasubot.storage.from('public').remove(['example.txt']);
print('deleted file id : ${deleteFileResponse.first.id}');
// Local file cleanup
if (file.existsSync()) file.deleteSync();
}