Skip to content

Commit 21f4205

Browse files
committed
Update READMEs
1 parent bcbebe9 commit 21f4205

File tree

8 files changed

+132
-24
lines changed

8 files changed

+132
-24
lines changed

packages/powersync/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<a href="https://www.powersync.com" target="_blank"><img src="https://github.com/powersync-ja/.github/assets/7372448/d2538c43-c1a0-4c47-9a76-41462dba484f"/></a>
33
</p>
44

5-
# PowerSync SDK for Dart/Flutter
5+
# PowerSync SDK for Flutter
66

77
_[PowerSync](https://www.powersync.com) is a sync engine for building local-first apps with instantly-responsive UI/UX and simplified state transfer. Syncs between SQLite on the client-side and Postgres or MongoDB on the server-side (MySQL coming soon)._
88

packages/powersync/example/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Examples
22

3-
* [Getting started](./getting_started.dart)
4-
* [Watching queries](./watching_changes.dart)
5-
* [Batch writes](./batch_writes.dart)
3+
- [Getting started](./getting_started.dart)
4+
- [Watching queries](./watching_changes.dart)
5+
- [Batch writes](./batch_writes.dart)

packages/powersync_core/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
<a href="https://www.powersync.com" target="_blank"><img src="https://github.com/powersync-ja/.github/assets/7372448/d2538c43-c1a0-4c47-9a76-41462dba484f"/></a>
33
</p>
44

5-
# PowerSync SDK for Dart/Flutter
5+
# PowerSync SDK for Dart
66

77
_[PowerSync](https://www.powersync.com) is a sync engine for building local-first apps with instantly-responsive UI/UX and simplified state transfer. Syncs between SQLite on the client-side and Postgres or MongoDB on the server-side (MySQL coming soon)._
88

99
This package (`powersync_core`) is the PowerSync client SDK for Dart.
1010

11+
> **Note**
12+
>
13+
> This is a Dart library for Powersync for use cases such as server-side Dart or non-Flutter Dart environments.
14+
>
15+
> If you are developing a Flutter application, use [powersync](https://pub.dev/packages/powersync) or [powersync_sqlcipher](https://pub.dev/packages/powersync_sqlcipher) instead. The `powersync_core` package is for non-Flutter Dart environments.
16+
1117
# Installation
1218

1319
```bash
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Examples
2+
3+
- [Getting started](./getting_started.dart)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import 'dart:io';
2+
3+
import 'package:powersync_core/powersync_core.dart';
4+
import 'package:path/path.dart';
5+
6+
const schema = Schema([
7+
Table('customers', [Column.text('name'), Column.text('email')])
8+
]);
9+
10+
late PowerSyncDatabase db;
11+
12+
// Setup connector to backend if you would like to sync data.
13+
class BackendConnector extends PowerSyncBackendConnector {
14+
PowerSyncDatabase db;
15+
16+
BackendConnector(this.db);
17+
@override
18+
// ignore: body_might_complete_normally_nullable
19+
Future<PowerSyncCredentials?> fetchCredentials() async {
20+
// implement fetchCredentials
21+
}
22+
@override
23+
Future<void> uploadData(PowerSyncDatabase database) async {
24+
// implement uploadData
25+
}
26+
}
27+
28+
openDatabase() async {
29+
const dbFilename = 'powersync-demo.db';
30+
final dir = (Directory.current.uri).toFilePath();
31+
var path = join(dir, dbFilename);
32+
33+
// Setup the database.
34+
db = PowerSyncDatabase(schema: schema, path: path);
35+
await db.initialize();
36+
37+
// Run local statements.
38+
await db.execute(
39+
'INSERT INTO customers(id, name, email) VALUES(uuid(), ?, ?)',
40+
['Fred', 'fred@example.org']);
41+
42+
// Connect to backend
43+
db.connect(connector: BackendConnector(db));
44+
}

packages/powersync_sqlcipher/README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<a href="https://www.powersync.com" target="_blank"><img src="https://github.com/powersync-ja/.github/assets/7372448/d2538c43-c1a0-4c47-9a76-41462dba484f"/></a>
33
</p>
44

5-
# PowerSync with SQLCipher SDK for Dart/Flutter
5+
# PowerSync with SQLCipher SDK for Flutter
66

77
_[PowerSync](https://www.powersync.com) is a sync engine for building local-first apps with instantly-responsive UI/UX and simplified state transfer. Syncs between SQLite on the client-side and Postgres or MongoDB on the server-side (MySQL coming soon)._
88

@@ -18,42 +18,44 @@ flutter pub add powersync_sqlcipher
1818

1919
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.
2020

21-
### Demo app
21+
This SDK requires a slightly different setup in order to encrypt the local database.
2222

23-
The easiest way to test out the alpha is to run the [Supabase Todo-List](./demos/supabase-todolist) demo app:
23+
### Usage
2424

25-
1. Checkout [this repo's](https://github.com/powersync-ja/powersync.dart/tree/master) `master` branch.
25+
```Dart
26+
import 'package/powersync_sqlcipher/powersync.dart';
2627
27-
- Note: If you are an existing user updating to the latest code after a git pull, run `melos exec 'flutter pub upgrade'` in the repo's root and make sure it succeeds.
28+
/// Global reference to the database
29+
late final PowerSyncDatabase db;
2830
29-
2. Run `melos prepare` in the repo's root
30-
3. cd into the `demos/supabase-todolist` folder
31-
4. If you haven’t yet: `cp lib/app_config_template.dart lib/app_config.dart` (optionally update this config with your own Supabase and PowerSync project details).
32-
5. Run `flutter run -d chrome`
31+
final cipherFactory = PowerSyncSQLCipherOpenFactory(
32+
path: path, key: "sqlcipher-encryption-key");
33+
34+
db = PowerSyncDatabase.withFactory(cipherFactory, schema: schema);
35+
```
3336

3437
### Installing PowerSync in your own project
3538

3639
Install the latest version of the package, for example:
3740

3841
```
39-
flutter pub add powersync_sqlcipher:'^0.1.0'
42+
flutter pub add powersync_sqlcipher: ^0.1.0
4043
```
4144

4245
The latest version can be found [here](https://pub.dev/packages/powersync_sqlcipher/versions).
4346

44-
### Usage
47+
### Demo app
4548

46-
```Dart
47-
import 'package/powersync_sqlcipher/powersync.dart';
49+
The easiest way to test out the powersync is to run the [Supabase Todo-List](./demos/supabase-todolist) demo app:
4850

49-
/// Global reference to the database
50-
late final PowerSyncDatabase db;
51+
1. Checkout [this repo's](https://github.com/powersync-ja/powersync.dart/tree/master) `master` branch.
5152

52-
final cipherFactory = PowerSyncSQLCipherOpenFactory(
53-
path: await getDatabasePath(), key: "fkdjskjnfds");
53+
- Note: If you are an existing user updating to the latest code after a git pull, run `melos exec 'flutter pub upgrade'` in the repo's root and make sure it succeeds.
5454

55-
db = PowerSyncDatabase.withFactory(cipherFactory, schema: schema);
56-
```
55+
2. Run `melos prepare` in the repo's root
56+
3. cd into the `demos/supabase-todolist` folder
57+
4. If you haven’t yet: `cp lib/app_config_template.dart lib/app_config.dart` (optionally update this config with your own Supabase and PowerSync project details).
58+
5. Run `flutter run -d chrome`
5759

5860
[comment]: # "The sections below need to be updated"
5961

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import 'package:flutter/foundation.dart';
2+
import 'package:powersync_sqlcipher/powersync.dart';
3+
import 'package:path_provider/path_provider.dart';
4+
import 'package:path/path.dart';
5+
6+
const schema = Schema([
7+
Table('customers', [Column.text('name'), Column.text('email')])
8+
]);
9+
10+
late PowerSyncDatabase db;
11+
12+
// Setup connector to backend if you would like to sync data.
13+
class BackendConnector extends PowerSyncBackendConnector {
14+
PowerSyncDatabase db;
15+
16+
BackendConnector(this.db);
17+
@override
18+
// ignore: body_might_complete_normally_nullable
19+
Future<PowerSyncCredentials?> fetchCredentials() async {
20+
// implement fetchCredentials
21+
}
22+
@override
23+
Future<void> uploadData(PowerSyncDatabase database) async {
24+
// implement uploadData
25+
}
26+
}
27+
28+
openDatabase() async {
29+
var path = 'powersync-demo.db';
30+
// getApplicationSupportDirectory is not supported on Web
31+
if (!kIsWeb) {
32+
final dir = await getApplicationSupportDirectory();
33+
path = join(dir.path, 'powersync-dart.db');
34+
}
35+
36+
// Setup the database.
37+
final cipherFactory = PowerSyncSQLCipherOpenFactory(
38+
path: path, key: "sqlcipher-encryption-key");
39+
40+
db = PowerSyncDatabase.withFactory(cipherFactory, schema: schema);
41+
42+
await db.initialize();
43+
44+
// Run local statements.
45+
await db.execute(
46+
'INSERT INTO customers(id, name, email) VALUES(uuid(), ?, ?)',
47+
['Fred', 'fred@example.org']);
48+
49+
// Connect to backend
50+
db.connect(connector: BackendConnector(db));
51+
}

packages/powersync_sqlcipher/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ dev_dependencies:
2020
sdk: flutter
2121
flutter_lints: ^3.0.0
2222
test_api: ^0.7.0
23+
path: ^1.8.3
24+
path_provider: ^2.0.13
2325

2426
platforms:
2527
android:

0 commit comments

Comments
 (0)