pasubot 0.0.1 copy "pasubot: ^0.0.1" to clipboard
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();
}
0
likes
130
points
6
downloads

Publisher

unverified uploader

Weekly Downloads

A dart client for Pasubot. This client makes it simple for developers to build secure and scalable products.

Documentation

API reference

License

MIT (license)

Dependencies

http, mongorest, pasubot_functions_client, pasubot_gotrue, pasubot_json_isolate, pasubot_realtime_client, pasubot_storage_client, rxdart

More

Packages that depend on pasubot