Skip to content

Commit 8cdf589

Browse files
authored
Merge branch 'docs' into prioritized-sync
2 parents 11191a0 + 9b19b90 commit 8cdf589

File tree

83 files changed

+1169
-485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1169
-485
lines changed

.github/workflows/check.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Check Documentation
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
tags-ignore:
8+
- '**'
9+
10+
jobs:
11+
check:
12+
name: Check Documentation
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
21+
# This checks internal links, but does not validate external links
22+
- name: Check for broken links
23+
run: npx mintlify broken-links

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
.vscode/
3+
.idea

architecture/client-architecture.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ The local SQLite database embedded in the PowerSync SDK is automatically kept in
3131

3232
Client-side data modifications, namely updates, deletes and inserts, are persisted in the embedded SQLite database as well as stored in an upload queue. The upload queue is a blocking [FIFO](https://en.wikipedia.org/wiki/FIFO%5F%28computing%5Fand%5Felectronics%29) queue that gets processed when network connectivity is available.
3333

34-
Each entry in the queue is processed by writing the entry to your existing backend application API, using a function [defined by you](/usage/installation/client-side-setup/integrating-with-your-backend) (the developer). This is to ensure that existing backend business logic is honored when uploading data changes. For more information, see the section on [integrating with your backend](/usage/installation/client-side-setup/integrating-with-your-backend).
34+
Each entry in the queue is processed by writing the entry to your existing backend application API, using a function [defined by you](/installation/client-side-setup/integrating-with-your-backend) (the developer). This is to ensure that existing backend business logic is honored when uploading data changes. For more information, see the section on [integrating with your backend](/installation/client-side-setup/integrating-with-your-backend).
3535

3636
<Frame>
3737
<img src="/images/powersync-docs-architecture-diagram-008 (3).png"/>
3838
</Frame>
3939

4040
### Schema
41-
On the client, the application [defines a schema](/usage/installation/client-side-setup/define-your-schema) with tables, columns and indexes.
41+
On the client, the application [defines a schema](/installation/client-side-setup/define-your-schema) with tables, columns and indexes.
4242

4343
These are then usable as if they were actual SQLite tables, while in reality these are created as SQLite views.
4444

architecture/powersync-service.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Replication is initially performed by taking a snapshot of all tables defined in
1818

1919
## Authentication
2020

21-
The service authenticates users using [JWTs](/usage/installation/authentication-setup), before allowing access to data.
21+
The service authenticates users using [JWTs](/installation/authentication-setup), before allowing access to data.
2222

2323
## Streaming Sync
2424

client-sdk-references/flutter.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ See the [SDK's README](https://pub.dev/packages/powersync#getting-started) for i
4141
Before implementing the PowerSync SDK in your project, make sure you have completed these steps:
4242

4343
* Signed up for a PowerSync Cloud account ([here](https://accounts.journeyapps.com/portal/get-started?powersync=true)) or [self-host PowerSync](/self-hosting/getting-started).
44-
* [Configured your backend database](/usage/installation/database-setup) and connected it to your PowerSync instance.
44+
* [Configured your backend database](/installation/database-setup) and connected it to your PowerSync instance.
4545
* [Installed](/client-sdk-references/flutter#installation) the PowerSync Flutter SDK.
4646

4747
### 1\. Define the Schema
@@ -130,14 +130,14 @@ The PowerSync backend connector provides the connection between your application
130130

131131
It is used to:
132132

133-
1. [Retrieve an auth token](/usage/installation/authentication-setup) to connect to the PowerSync instance.
134-
2. [Apply local changes](/usage/installation/app-backend-setup/writing-client-changes) on your backend application server (and from there, to Postgres)
133+
1. [Retrieve an auth token](/installation/authentication-setup) to connect to the PowerSync instance.
134+
2. [Apply local changes](/installation/app-backend-setup/writing-client-changes) on your backend application server (and from there, to Postgres)
135135

136136
Accordingly, the connector must implement two methods:
137137

138-
1. [PowerSyncBackendConnector.fetchCredentials](https://pub.dev/documentation/powersync/latest/powersync/PowerSyncBackendConnector/fetchCredentials.html) \- This is called every couple of minutes and is used to obtain credentials for your app backend API. -> See [Authentication Setup](/usage/installation/authentication-setup) for instructions on how the credentials should be generated.
138+
1. [PowerSyncBackendConnector.fetchCredentials](https://pub.dev/documentation/powersync/latest/powersync/PowerSyncBackendConnector/fetchCredentials.html) \- This is called every couple of minutes and is used to obtain credentials for your app backend API. -> See [Authentication Setup](/installation/authentication-setup) for instructions on how the credentials should be generated.
139139
2. [PowerSyncBackendConnector.uploadData](https://pub.dev/documentation/powersync/latest/powersync/PowerSyncBackendConnector/uploadData.html) \- Use this to upload client-side changes to your app backend.
140-
\-> See [Writing Client Changes](/usage/installation/app-backend-setup/writing-client-changes) for considerations on the app backend implementation.
140+
\-> See [Writing Client Changes](/installation/app-backend-setup/writing-client-changes) for considerations on the app backend implementation.
141141

142142
**Example**:
143143

@@ -156,14 +156,14 @@ class MyBackendConnector extends PowerSyncBackendConnector {
156156
Future<PowerSyncCredentials?> fetchCredentials() async {
157157
// Implement fetchCredentials to obtain a JWT from your authentication service
158158
// If you're using Supabase or Firebase, you can re-use the JWT from those clients, see
159-
// - https://docs.powersync.com/usage/installation/authentication-setup/supabase-auth
160-
// - https://docs.powersync.com/usage/installation/authentication-setup/firebase-auth
159+
// - https://docs.powersync.com/installation/authentication-setup/supabase-auth
160+
// - https://docs.powersync.com/installation/authentication-setup/firebase-auth
161161
162162
// See example implementation here: https://pub.dev/documentation/powersync/latest/powersync/DevConnector/fetchCredentials.html
163163
164164
return {
165165
endpoint: '[Your PowerSync instance URL or self-hosted endpoint]',
166-
// Use a development token (see Authentication Setup https://docs.powersync.com/usage/installation/authentication-setup/development-tokens) to get up and running quickly
166+
// Use a development token (see Authentication Setup https://docs.powersync.com/installation/authentication-setup/development-tokens) to get up and running quickly
167167
token: 'An authentication token'
168168
};
169169
}

client-sdk-references/flutter/flutter-orm-support.mdx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
---
22
title: "Flutter ORM Support (Alpha)"
3+
sidebarTitle: "ORM Support (Alpha)"
34
---
45

6+
An introduction to using ORMs with PowerSync is available on our blog [here](https://www.powersync.com/blog/using-orms-with-powersync).
7+
58
ORM support is available via the following package (currently in an alpha release):
69

710
<Card
@@ -39,10 +42,3 @@ Every write transaction (or write statement) will lock the database for other wr
3942
**External modifications**
4043

4144
Often, ORMs only detect notifications made using the same library. In order to support streaming queries, PowerSync requires the ORM to allow external modifications to trigger the same change notifications, meaning streaming queries are unlikely to work out-of-the-box.
42-
43-
<Check>
44-
**Further reading**
45-
46-
See [Using ORMs with PowerSync](https://www.powersync.com/blog/using-orms-with-powersync) on our blog.
47-
48-
</Check>

client-sdk-references/flutter/flutter-web-support.mdx

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
---
2-
title: "Flutter Web Support (Alpha)"
2+
title: "Flutter Web Support (Beta)"
3+
sidebarTitle: "Web Support (Beta)"
34
---
45

5-
Web support for Flutter in version `^1.6.0` is currently in its alpha stage.
6+
<Note>
7+
Web support for Flutter in version `^1.9.0` is currently in a **beta** release. It is functionally ready for production use, provided that you've tested your use cases.
8+
9+
Please see the [Limitations](#limitations) detailed below.
10+
</Note>
611

712
## Demo app
813

9-
The easiest way to test out the alpha is to run the [Supabase Todo-List](https://github.com/powersync-ja/powersync.dart/blob/master/demos/supabase-todolist) demo app:
14+
The easiest way to test Flutter Web support is to run the [Supabase Todo-List](https://github.com/powersync-ja/powersync.dart/tree/main/demos/supabase-todolist) demo app:
1015

11-
1. Checkout [the powersync.dart repo's](https://github.com/powersync-ja/powersync.dart/tree/master) `master` branch.
16+
1. Clone the [powersync.dart](https://github.com/powersync-ja/powersync.dart/tree/main) repo.
1217
1. **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.
1318
2. Run `melos prepare` in the repo's root
1419
3. cd into the `demos/supabase-todolist` folder
@@ -17,25 +22,56 @@ The easiest way to test out the alpha is to run the [Supabase Todo-List](https:/
1722

1823
## Installing PowerSync in your own project
1924

20-
Install the latest alpha version of the package, for example:
25+
Install the [latest version](https://pub.dev/packages/powersync/versions) of the package, for example:
2126

2227
```bash
23-
flutter pub add powersync:'^1.6.2'
28+
flutter pub add powersync:'^1.9.0'
2429
```
2530

26-
The latest version can be found [here](https://pub.dev/packages/powersync/versions).
27-
28-
## Additional config
31+
### Additional config
2932

30-
Web support requires `sqlite3.wasm` and `powersync_db.worker.js` assets to be served from the web application. They can be downloaded to the `web` directory by running the following command in your application's root folder.
33+
#### Assets
34+
Web support requires `sqlite3.wasm` and worker (`powersync_db.worker.js` and `powersync_sync.worker.js`) assets to be served from the web application. They can be downloaded to the web directory by running the following command in your application's root folder.
3135

3236
```bash
3337
dart run powersync:setup_web
3438
```
3539

3640
The same code is used for initializing native and web `PowerSyncDatabase` clients.
3741

38-
## Imports
42+
#### OPFS for improved performance
43+
44+
This SDK supports different storage modes of the SQLite database with varying levels of performance and compatibility:
45+
46+
- **IndexedDB**: Highly compatible with different browsers, but performance is slow.
47+
- **OPFS** (Origin-Private File System): Significantly faster but requires additional configuration.
48+
49+
OPFS is the preferred mode when it is available. Otherwise database storage falls back to IndexedDB.
50+
51+
Enabling OPFS requires adding two headers to the HTTP server response when a client requests the Flutter web application:
52+
53+
- `Cross-Origin-Opener-Policy`: Needs to be set to `same-origin`.
54+
- `Cross-Origin-Embedder-Policy`: Needs to be set to `require-corp`.
55+
56+
When running the app locally, you can use the following command to include the required headers:
57+
58+
```bash
59+
flutter run -d chrome --web-header "Cross-Origin-Opener-Policy=same-origin" --web-header "Cross-Origin-Embedder-Policy=require-corp"
60+
```
61+
62+
When serving a Flutter Web app in production, the [Flutter docs](https://docs.flutter.dev/deployment/web#building-the-app-for-release) recommend building the web app with `flutter build web`, then serving the content with an HTTP server. The server should be configured to use the above headers.
63+
64+
<Tip>
65+
**Further reading**:
66+
67+
[Drift](https://drift.simonbinder.eu/) uses the same packages as our [`sqlite_async`](https://github.com/powersync-ja/sqlite_async.dart) package under the hood, and has excellent documentation for how the web filesystem is selected. See [here](https://drift.simonbinder.eu/platforms/web/) for web compatibility notes and [here](https://drift.simonbinder.eu/platforms/web/#additional-headers) for additional notes on the required web headers.
68+
</Tip>
69+
70+
## Limitations
71+
72+
The API for Web is essentially the same as for native platforms, however, some features within `PowerSyncDatabase` clients are not available.
73+
74+
### Imports
3975

4076
Flutter Web does not support importing directly from `sqlite3.dart` as it uses `dart:ffi`.
4177

@@ -53,14 +89,8 @@ import 'package/powersync/sqlite3_common.dart'
5389

5490
in code which needs to run on the Web platform. Isolated native-specific code can still import from `sqlite3.dart`.
5591

56-
## Database connections
92+
### Database connections
5793

5894
Web database connections do not support concurrency. A single database connection is used. `readLock` and `writeLock` contexts do not implement checks for preventing writable queries in read connections and vice-versa.
5995

6096
Direct access to the synchronous `CommonDatabase` (`sqlite.Database` equivalent for web) connection is not available. `computeWithDatabase` is not available on web.
61-
62-
## Limitations
63-
64-
The API for web is essentially the same as for native platforms. Some features within `PowerSyncDatabase` clients are not available.
65-
66-
Full multiple tab support is not yet available. Some sync status indicators will not be available in each tab. Multiple requests from tabs to connect/disconnect might result in undefined behaviour.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: "Unit Testing"
3+
description: "Guidelines for unit testing with PowerSync"
4+
---
5+
6+
For unit-testing your projects using PowerSync
7+
(e.g. testing whether your queries run as expected) you will need the `powersync-sqlite-core` binary in your project's root directory.
8+
9+
1. Download the PowerSync SQLite binary
10+
- Go to the [Releases](https://github.com/powersync-ja/powersync-sqlite-core/releases) for `powersync-sqlite-core`.
11+
- Download the binary compatible with your OS.
12+
2. Rename the binary
13+
- Rename the binary by removing the architecture suffix.
14+
- Example: `powersync_x64.dll` to `powersync.dll`
15+
- Example: `libpowersync_aarch64.dylib` to `libpowersync.dylib`
16+
- Example: `libpowersync_x64.so` to `libpowersync.so`
17+
3. Place the binary in your project
18+
- Move the renamed binary to the root directory of your project.
19+
20+
This snippet below is only included as a guide to unit testing in Flutter with PowerSync. For more information refer to the [official Flutter unit testing documentation](https://docs.flutter.dev/cookbook/testing/unit/introduction).
21+
22+
```dart
23+
import 'dart:io';
24+
import 'package:powersync/powersync.dart';
25+
import 'package:path/path.dart';
26+
27+
const schema = Schema([
28+
Table('customers', [Column.text('name'), Column.text('email')])
29+
]);
30+
31+
late PowerSyncDatabase testDB;
32+
33+
String getTestDatabasePath() async {
34+
const dbFilename = 'powersync-test.db';
35+
final dir = Directory.current.absolute.path;
36+
return join(dir, dbFilename);
37+
}
38+
39+
Future<void> openTestDatabase() async {
40+
testDB = PowerSyncDatabase(
41+
schema: schema,
42+
path: await getTestDatabasePath(),
43+
logger: testLogger,
44+
);
45+
46+
await testDB.initialize();
47+
}
48+
49+
test('INSERT', () async {
50+
await testDB.execute(
51+
'INSERT INTO customers(name, email) VALUES(?, ?)', ['John Doe', '[email protected]']);
52+
53+
final results = await testDB.getAll('SELECT * FROM customers');
54+
55+
expect(results.length, 1);
56+
expect(results, ['John Doe', '[email protected]']);
57+
});
58+
```
59+
60+
#### If you have trouble with loading the extension, confirm the following
61+
62+
Ensure that your SQLite3 binary install on your system has extension loading enabled. You can confirm this by doing the following
63+
64+
- Run `sqlite3` in your command-line interface.
65+
- In the sqlite3 prompt run `PRAGMA compile_options;`
66+
- Check the output for the option `ENABLE_LOAD_EXTENSION`.
67+
- If you see `ENABLE_LOAD_EXTENSION`, it means extension loading is enabled.
68+
69+
If the above steps don't work, you can also confirm if extension loading is enabled by trying to load the extension in your command-line interface.
70+
71+
- Run `sqlite3` in your command-line interface.
72+
- Run `.load /path/to/file/libpowersync.dylib` (macOS) or `.load /path/to/file/libpowersync.so` (Linux) or `.load /path/to/file/powersync.dll` (Windows).
73+
- If this runs without error, then extension loading is enabled. If it fails with an error message about extension loading being disabled, then it’s not enabled in your SQLite installation.
74+
75+
If it is not enabled, you will have to download a compiled SQLite binary with extension loading enabled (e.g. using Homebrew) or [compile SQLite](https://www.sqlite.org/howtocompile.html) with extension loading enabled and
76+
include it in your project's folder alongside the extension.

client-sdk-references/introduction.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ Select your client framework for the full SDK reference, getting started instruc
1010
</Card>
1111
<Card title="React Native & Expo" icon="react" href="/client-sdk-references/react-native-and-expo">
1212
</Card>
13-
<Card title="JS/Web" icon="js" href="/client-sdk-references/js-web">
13+
<Card title="JavaScript/Web" icon="js" href="/client-sdk-references/javascript-web">
1414
</Card>
1515
<Card title="Kotlin Multiplatform" icon="flag" href="/client-sdk-references/kotlin-multiplatform">
1616
Currently in a beta release.
1717
</Card>
1818
<Card title="Swift" icon="swift" href="/client-sdk-references/swift">
1919
Currently in an alpha release.
2020
</Card>
21-
</CardGroup>
21+
</CardGroup>

0 commit comments

Comments
 (0)