diff --git a/demos/supabase-anonymous-auth/lib/app_config_template.dart b/demos/supabase-anonymous-auth/lib/app_config_template.dart index bce37c5a..41f9a7c8 100644 --- a/demos/supabase-anonymous-auth/lib/app_config_template.dart +++ b/demos/supabase-anonymous-auth/lib/app_config_template.dart @@ -1,5 +1,6 @@ +// 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..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,5 +1,6 @@ +// 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..d7ead31d 100644 --- a/demos/supabase-simple-chat/lib/app_config_template.dart +++ b/demos/supabase-simple-chat/lib/app_config_template.dart @@ -1,6 +1,7 @@ +// 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..ccfdfa21 100644 --- a/demos/supabase-todolist/lib/app_config_template.dart +++ b/demos/supabase-todolist/lib/app_config_template.dart @@ -1,9 +1,9 @@ +// 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 supabaseUrl = 'https://foo.supabase.co'; + static const String supabaseAnonKey = 'foo'; + static const String powersyncUrl = 'https://foo.powersync.journeyapps.com'; static const String supabaseStorageBucket = - ''; // Optional if you want to test out attachments + ''; // Optional. Only required when syncing attachments and using Supabase Storage. See packages/powersync_attachments_helper. } 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.