Skip to content

Commit 6792beb

Browse files
DominicGBauerDominicGBauer
andauthored
docs: update readme and getting started (#51)
* docs: update readme and getting started * docs: update readme and getting started * fix: lint issue --------- Co-authored-by: DominicGBauer <dominic@nomanini.com>
1 parent b94ba9f commit 6792beb

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

packages/powersync/README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ const schema = Schema([
2424
2525
late PowerSyncDatabase db;
2626
27+
// Setup connector to backend if you would like to sync data.
28+
class BackendConnector extends PowerSyncBackendConnector {
29+
PowerSyncDatabase db;
30+
31+
BackendConnector(this.db);
32+
@override
33+
Future<PowerSyncCredentials?> fetchCredentials() async {
34+
// implement fetchCredentials
35+
}
36+
@override
37+
Future<void> uploadData(PowerSyncDatabase database) async {
38+
// implement uploadData
39+
}
40+
}
41+
2742
openDatabase() async {
2843
final dir = await getApplicationSupportDirectory();
2944
final path = join(dir.path, 'powersync-dart.db');
@@ -35,20 +50,9 @@ openDatabase() async {
3550
await db.execute(
3651
'INSERT INTO customers(id, name, email) VALUES(uuid(), ?, ?)',
3752
['Fred', 'fred@example.org']);
38-
}
39-
40-
connectPowerSync() async {
41-
// DevConnector stores credentials in-memory by default.
42-
// Extend the class to persist credentials.
43-
final connector = DevConnector();
4453
45-
// Login in dev mode.
46-
await connector.devLogin(
47-
endpoint: 'https://myinstance.powersync.co',
48-
user: 'demo',
49-
password: 'demo');
5054
51-
// Connect to PowerSync service and start sync.
52-
db.connect(connector: connector);
55+
// Connect to backend
56+
db.connect(connector: BackendConnector(db));
5357
}
5458
```

packages/powersync/example/getting_started.dart

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ const schema = Schema([
88

99
late PowerSyncDatabase db;
1010

11+
// Setup connector to backend if you would like to sync data.
12+
class BackendConnector extends PowerSyncBackendConnector {
13+
PowerSyncDatabase db;
14+
15+
BackendConnector(this.db);
16+
@override
17+
// ignore: body_might_complete_normally_nullable
18+
Future<PowerSyncCredentials?> fetchCredentials() async {
19+
// implement fetchCredentials
20+
}
21+
@override
22+
Future<void> uploadData(PowerSyncDatabase database) async {
23+
// implement uploadData
24+
}
25+
}
26+
1127
openDatabase() async {
1228
final dir = await getApplicationSupportDirectory();
1329
final path = join(dir.path, 'powersync-dart.db');
@@ -19,19 +35,7 @@ openDatabase() async {
1935
await db.execute(
2036
'INSERT INTO customers(id, name, email) VALUES(uuid(), ?, ?)',
2137
['Fred', 'fred@example.org']);
22-
}
23-
24-
connectPowerSync() async {
25-
// DevConnector stores credentials in-memory by default.
26-
// Extend the class to persist credentials.
27-
final connector = DevConnector();
28-
29-
// Login in dev mode.
30-
await connector.devLogin(
31-
endpoint: 'https://myinstance.powersync.co',
32-
user: 'demo',
33-
password: 'demo');
3438

35-
// Connect to PowerSync service and start sync.
36-
db.connect(connector: connector);
39+
// Connect to backend
40+
db.connect(connector: BackendConnector(db));
3741
}

0 commit comments

Comments
 (0)