From 0ffe8e0807ab9d84f0cb521d292ddd861f069ed4 Mon Sep 17 00:00:00 2001 From: benitav Date: Tue, 20 Feb 2024 11:53:07 +0200 Subject: [PATCH 1/5] Improve credntials templates --- .../lib/app_config_template.dart | 9 ++++++--- .../lib/app_config_template.dart | 9 ++++++--- .../lib/app_config_template.dart | 12 ++++++++---- .../lib/app_config_template.dart | 15 ++++++++------- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/demos/supabase-anonymous-auth/lib/app_config_template.dart b/demos/supabase-anonymous-auth/lib/app_config_template.dart index bce37c5a..4e00929b 100644 --- a/demos/supabase-anonymous-auth/lib/app_config_template.dart +++ b/demos/supabase-anonymous-auth/lib/app_config_template.dart @@ -1,5 +1,8 @@ +/** + * Copy this template: `cp lib/app_config_template.dart lib/app_config.dart` + * Edit lib/app_config.dart and enter your Supabase and PowerSync project details. +*/ class AppConfig { - static const String supabaseUrl = 'https://jrimaqxlgrpjipgssldo.supabase.co'; - static const String supabaseAnonKey = - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImpyaW1hcXhsZ3JwamlwZ3NzbGRvIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTE1ODY5MTAsImV4cCI6MjAwNzE2MjkxMH0.K-Qb-YFz0oVpLshUEezGU-Do-sX08zKqBzVccDoZp_Y'; + static const String supabaseUrl = 'https://foo.supabase.co'; + static const String supabaseAnonKey = 'foo'; } diff --git a/demos/supabase-edge-function-auth/lib/app_config_template.dart b/demos/supabase-edge-function-auth/lib/app_config_template.dart index bce37c5a..4e00929b 100644 --- a/demos/supabase-edge-function-auth/lib/app_config_template.dart +++ b/demos/supabase-edge-function-auth/lib/app_config_template.dart @@ -1,5 +1,8 @@ +/** + * Copy this template: `cp lib/app_config_template.dart lib/app_config.dart` + * Edit lib/app_config.dart and enter your Supabase and PowerSync project details. +*/ class AppConfig { - static const String supabaseUrl = 'https://jrimaqxlgrpjipgssldo.supabase.co'; - static const String supabaseAnonKey = - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImpyaW1hcXhsZ3JwamlwZ3NzbGRvIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTE1ODY5MTAsImV4cCI6MjAwNzE2MjkxMH0.K-Qb-YFz0oVpLshUEezGU-Do-sX08zKqBzVccDoZp_Y'; + static const String supabaseUrl = 'https://foo.supabase.co'; + static const String supabaseAnonKey = 'foo'; } diff --git a/demos/supabase-simple-chat/lib/app_config_template.dart b/demos/supabase-simple-chat/lib/app_config_template.dart index 10dac15d..1ba0be62 100644 --- a/demos/supabase-simple-chat/lib/app_config_template.dart +++ b/demos/supabase-simple-chat/lib/app_config_template.dart @@ -1,6 +1,10 @@ +/** + * Copy this template: `cp lib/app_config_template.dart lib/app_config.dart` + * Edit lib/app_config.dart and enter your Supabase and PowerSync project details. +*/ class AppConfig { - static const String supabaseUrl = 'https://aaaaaaaaaaaa.supabase.co'; - static const String supabaseAnonKey = 'eyeyeyeyeyeye'; - static const String powersyncUrl = - 'https://65130c9db6679a3682ba380a.powersync.journeyapps.com'; + static const String supabaseUrl = 'https://foo.supabase.co'; + static const String supabaseAnonKey = 'foo'; + static const String powersyncUrl = 'https://foo.powersync.journeyapps.com'; } + diff --git a/demos/supabase-todolist/lib/app_config_template.dart b/demos/supabase-todolist/lib/app_config_template.dart index e38a6053..ef6eb246 100644 --- a/demos/supabase-todolist/lib/app_config_template.dart +++ b/demos/supabase-todolist/lib/app_config_template.dart @@ -1,9 +1,10 @@ +/** + * Copy this template: `cp lib/app_config_template.dart lib/app_config.dart` + * Edit lib/app_config.dart and enter your Supabase and PowerSync project details. +*/ class AppConfig { - static const String supabaseUrl = 'https://jrimaqxlgrpjipgssldo.supabase.co'; - static const String supabaseAnonKey = - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImpyaW1hcXhsZ3JwamlwZ3NzbGRvIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTE1ODY5MTAsImV4cCI6MjAwNzE2MjkxMH0.K-Qb-YFz0oVpLshUEezGU-Do-sX08zKqBzVccDoZp_Y'; - static const String powersyncUrl = - 'https://64d392172a3c226cddbd5070.powersync.journeyapps.com'; - static const String supabaseStorageBucket = - ''; // Optional if you want to test out attachments + static const String supabaseUrl = 'https://foo.supabase.co'; + static const String supabaseAnonKey = 'foo'; + static const String powersyncUrl = 'https://foo.powersync.journeyapps.com'; + static const String supabaseStorageBucket = ''; // Optional. Only required when syncing attachments with Supabase Storage. See packages/powersync_attachments_helper. } From a3d616b1306e1dd4d13b3e308e7734b56bcf7a3c Mon Sep 17 00:00:00 2001 From: benitav Date: Tue, 20 Feb 2024 11:55:43 +0200 Subject: [PATCH 2/5] Format comments correctly --- demos/supabase-anonymous-auth/lib/app_config_template.dart | 6 ++---- .../lib/app_config_template.dart | 6 ++---- demos/supabase-simple-chat/lib/app_config_template.dart | 6 ++---- demos/supabase-todolist/lib/app_config_template.dart | 6 ++---- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/demos/supabase-anonymous-auth/lib/app_config_template.dart b/demos/supabase-anonymous-auth/lib/app_config_template.dart index 4e00929b..41f9a7c8 100644 --- a/demos/supabase-anonymous-auth/lib/app_config_template.dart +++ b/demos/supabase-anonymous-auth/lib/app_config_template.dart @@ -1,7 +1,5 @@ -/** - * Copy this template: `cp lib/app_config_template.dart lib/app_config.dart` - * Edit lib/app_config.dart and enter your Supabase and PowerSync project details. -*/ +// Copy this template: `cp lib/app_config_template.dart lib/app_config.dart` +// Edit lib/app_config.dart and enter your Supabase and PowerSync project details. class AppConfig { static const String supabaseUrl = 'https://foo.supabase.co'; static const String supabaseAnonKey = 'foo'; diff --git a/demos/supabase-edge-function-auth/lib/app_config_template.dart b/demos/supabase-edge-function-auth/lib/app_config_template.dart index 4e00929b..41f9a7c8 100644 --- a/demos/supabase-edge-function-auth/lib/app_config_template.dart +++ b/demos/supabase-edge-function-auth/lib/app_config_template.dart @@ -1,7 +1,5 @@ -/** - * Copy this template: `cp lib/app_config_template.dart lib/app_config.dart` - * Edit lib/app_config.dart and enter your Supabase and PowerSync project details. -*/ +// Copy this template: `cp lib/app_config_template.dart lib/app_config.dart` +// Edit lib/app_config.dart and enter your Supabase and PowerSync project details. class AppConfig { static const String supabaseUrl = 'https://foo.supabase.co'; static const String supabaseAnonKey = 'foo'; diff --git a/demos/supabase-simple-chat/lib/app_config_template.dart b/demos/supabase-simple-chat/lib/app_config_template.dart index 1ba0be62..ee964d4f 100644 --- a/demos/supabase-simple-chat/lib/app_config_template.dart +++ b/demos/supabase-simple-chat/lib/app_config_template.dart @@ -1,7 +1,5 @@ -/** - * Copy this template: `cp lib/app_config_template.dart lib/app_config.dart` - * Edit lib/app_config.dart and enter your Supabase and PowerSync project details. -*/ +// Copy this template: `cp lib/app_config_template.dart lib/app_config.dart` +// Edit lib/app_config.dart and enter your Supabase and PowerSync project details. class AppConfig { static const String supabaseUrl = 'https://foo.supabase.co'; static const String supabaseAnonKey = 'foo'; diff --git a/demos/supabase-todolist/lib/app_config_template.dart b/demos/supabase-todolist/lib/app_config_template.dart index ef6eb246..bfb2e63e 100644 --- a/demos/supabase-todolist/lib/app_config_template.dart +++ b/demos/supabase-todolist/lib/app_config_template.dart @@ -1,7 +1,5 @@ -/** - * Copy this template: `cp lib/app_config_template.dart lib/app_config.dart` - * Edit lib/app_config.dart and enter your Supabase and PowerSync project details. -*/ +// Copy this template: `cp lib/app_config_template.dart lib/app_config.dart` +// Edit lib/app_config.dart and enter your Supabase and PowerSync project details. class AppConfig { static const String supabaseUrl = 'https://foo.supabase.co'; static const String supabaseAnonKey = 'foo'; From a00789911b4a8cf2084f7d41ca2ea5cc0e852558 Mon Sep 17 00:00:00 2001 From: benitav Date: Wed, 21 Feb 2024 08:54:42 +0200 Subject: [PATCH 3/5] Update demos/supabase-todolist/lib/app_config_template.dart --- demos/supabase-todolist/lib/app_config_template.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/supabase-todolist/lib/app_config_template.dart b/demos/supabase-todolist/lib/app_config_template.dart index bfb2e63e..be2e980e 100644 --- a/demos/supabase-todolist/lib/app_config_template.dart +++ b/demos/supabase-todolist/lib/app_config_template.dart @@ -4,5 +4,5 @@ class AppConfig { static const String supabaseUrl = 'https://foo.supabase.co'; static const String supabaseAnonKey = 'foo'; static const String powersyncUrl = 'https://foo.powersync.journeyapps.com'; - static const String supabaseStorageBucket = ''; // Optional. Only required when syncing attachments with Supabase Storage. See packages/powersync_attachments_helper. + static const String supabaseStorageBucket = ''; // Optional. Only required when syncing attachments and using Supabase Storage. See packages/powersync_attachments_helper. } From a8e977286850e42e1321e91f5f187911712bbdad Mon Sep 17 00:00:00 2001 From: benitav Date: Tue, 30 Apr 2024 19:32:50 +0200 Subject: [PATCH 4/5] Leaner Readme --- packages/powersync/README.md | 158 +++++------------------------------ 1 file changed, 23 insertions(+), 135 deletions(-) diff --git a/packages/powersync/README.md b/packages/powersync/README.md index 611a54a8..04ac65ac 100644 --- a/packages/powersync/README.md +++ b/packages/powersync/README.md @@ -1,151 +1,39 @@ -# PowerSync SDK for Dart/Flutter - -[PowerSync](https://powersync.co) is a service and set of SDKs that keeps PostgreSQL databases in sync with on-device SQLite databases. - -## SDK Features - -* Real-time streaming of changes. -* Direct access to the SQLite database - use SQL on the client and server. -* Operations are asynchronous by default - does not block the UI. -* Supports one write and many reads concurrently. -* No need for client-side database migrations - these are handled automatically. -* Subscribe to queries for live updates. - -## Examples - -For complete app examples, see our [example app gallery](https://docs.powersync.com/resources/demo-apps-example-projects#flutter) - -For examples of some common patterns, see our [example snippets](./example/README.md) - -## Getting started +

+ +

-You'll need to create a PowerSync account and set up a PowerSync instance. You can do this at [https://www.powersync.com/](https://www.powersync.com/). - -### Install the package +# PowerSync SDK for Dart/Flutter -`flutter pub add powersync` +[PowerSync](https://powersync.com) is a service and set of SDKs that keeps Postgres databases in sync with on-device SQLite databases. -### Implement a backend connector and initialize the PowerSync database +This package (`powersync`) is the PowerSync SDK for Dart/Flutter clients. -```dart -import 'package:powersync/powersync.dart'; -import 'package:path_provider/path_provider.dart'; -import 'package:path/path.dart'; +See a summary of features [here](https://docs.powersync.com/client-sdk-references/flutter). -// Define the schema for the local SQLite database. -// You can automatically generate this schema based on your sync rules: -// In the PowerSync dashboard, right-click on your PowerSync instance and then click "Generate client-side schema" -const schema = Schema([ - Table('customers', [Column.text('name'), Column.text('email')]) -]); +# Installation -late PowerSyncDatabase db; +```bash +flutter pub add powersync +``` -// You must implement a backend connector to define how PowerSync communicates with your backend. -class MyBackendConnector extends PowerSyncBackendConnector { - PowerSyncDatabase db; +# Getting Started - MyBackendConnector(this.db); - @override - Future fetchCredentials() async { - // implement fetchCredentials to obtain a JWT from your authentication service - // see https://docs.powersync.com/usage/installation/authentication-setup - } - @override - Future uploadData(PowerSyncDatabase database) async { - // Implement uploadData to send local changes to your backend service - // You can omit this method if you only want to sync data from the server to the client - // see https://docs.powersync.com/usage/installation/upload-data - } -} +Our [full SDK reference](https://docs.powersync.com/client-sdk-references/flutter) contains everything you need to know to get started implementing PowerSync in your project. -openDatabase() async { - final dir = await getApplicationSupportDirectory(); - final path = join(dir.path, 'powersync-dart.db'); +# Changelog - // Setup the database. - db = PowerSyncDatabase(schema: schema, path: path); - await db.initialize(); +A changelog for this SDK is available [here](https://releases.powersync.com/announcements/flutter-client-sdk). - // Connect to backend - db.connect(connector: MyBackendConnector(db)); -} -``` +# API Reference -### Subscribe to changes in data - -```dart -StreamBuilder( - // you can watch any SQL query - stream: return db.watch('SELECT * FROM customers order by id asc'), - builder: (context, snapshot) { - if (snapshot.hasData) { - // TODO: implement your own UI here based on the result set - return ...; - } else { - return const Center(child: CircularProgressIndicator()); - } - }, -) -``` +The full API reference for this SDK can be found [here](https://pub.dev/documentation/powersync/latest/powersync/powersync-library.html). -### Insert, update, and delete data in the SQLite database as you would normally - -```dart -FloatingActionButton( - onPressed: () async { - await db.execute( - 'INSERT INTO customers(id, name, email) VALUES(uuid(), ?, ?)', - ['Fred', 'fred@example.org'], - ); - }, - tooltip: '+', - child: const Icon(Icons.add), -); -``` +# Examples -### Send changes in local data to your backend service - -```dart -// Implement the uploadData method in your backend connector -@override -Future uploadData(PowerSyncDatabase database) async { - final batch = await database.getCrudBatch(); - if (batch == null) return; - for (var op in batch.crud) { - switch (op.op) { - case UpdateType.put: - // Send the data to your backend service - // replace `_myApi` with your own API client or service - await _myApi.put(op.table, op.opData!); - break; - default: - // TODO: implement the other operations (patch, delete) - break; - } - } - await batch.complete(); -} -``` +For example projects built with PowerSync and Flutter, see our [Demo Apps / Example Projects](https://docs.powersync.com/resources/demo-apps-example-projects#flutter) gallery. Most of these projects can also be found in the [`demos/`](../demos/) directory. -### Logging - -You can enable logging to see what's happening under the hood -or to debug connection/authentication/sync issues. - -```dart -Logger.root.level = Level.INFO; -Logger.root.onRecord.listen((record) { - if (kDebugMode) { - print('[${record.loggerName}] ${record.level.name}: ${record.time}: ${record.message}'); - - if (record.error != null) { - print(record.error); - } - if (record.stackTrace != null) { - print(record.stackTrace); - } - } -}); -``` +# Found a bug or need help? +- Join our [Discord server](https://discord.gg/powersync) where you can browse topics from our community, ask questions, share feedback, or just say hello :) +- Please open a [GitHub issue](https://github.com/powersync-ja/powersync.dart/issues) when you come across a bug. +- Have feedback or an idea? [Submit an idea](https://roadmap.powersync.com/tabs/5-roadmap/submit-idea) via our public roadmap or [schedule a chat](https://calendly.com/powersync/powersync-chat) with someone from our product team. From 3be82c6904f52ec2641a32a17a0b90a524af12b4 Mon Sep 17 00:00:00 2001 From: benitav Date: Tue, 30 Apr 2024 19:45:57 +0200 Subject: [PATCH 5/5] Run melos format --- demos/supabase-simple-chat/lib/app_config_template.dart | 1 - demos/supabase-todolist/lib/app_config_template.dart | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/demos/supabase-simple-chat/lib/app_config_template.dart b/demos/supabase-simple-chat/lib/app_config_template.dart index ee964d4f..d7ead31d 100644 --- a/demos/supabase-simple-chat/lib/app_config_template.dart +++ b/demos/supabase-simple-chat/lib/app_config_template.dart @@ -5,4 +5,3 @@ class AppConfig { static const String supabaseAnonKey = 'foo'; static const String powersyncUrl = 'https://foo.powersync.journeyapps.com'; } - diff --git a/demos/supabase-todolist/lib/app_config_template.dart b/demos/supabase-todolist/lib/app_config_template.dart index be2e980e..ccfdfa21 100644 --- a/demos/supabase-todolist/lib/app_config_template.dart +++ b/demos/supabase-todolist/lib/app_config_template.dart @@ -4,5 +4,6 @@ class AppConfig { static const String supabaseUrl = 'https://foo.supabase.co'; static const String supabaseAnonKey = 'foo'; static const String powersyncUrl = 'https://foo.powersync.journeyapps.com'; - static const String supabaseStorageBucket = ''; // Optional. Only required when syncing attachments and using Supabase Storage. See packages/powersync_attachments_helper. + static const String supabaseStorageBucket = + ''; // Optional. Only required when syncing attachments and using Supabase Storage. See packages/powersync_attachments_helper. }