You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: architecture/client-architecture.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,14 +31,14 @@ The local SQLite database embedded in the PowerSync SDK is automatically kept in
31
31
32
32
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.
33
33
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).
Copy file name to clipboardExpand all lines: client-sdk-references/flutter.mdx
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ See the [SDK's README](https://pub.dev/packages/powersync#getting-started) for i
41
41
Before implementing the PowerSync SDK in your project, make sure you have completed these steps:
42
42
43
43
* 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.
45
45
*[Installed](/client-sdk-references/flutter#installation) the PowerSync Flutter SDK.
46
46
47
47
### 1\. Define the Schema
@@ -130,14 +130,14 @@ The PowerSync backend connector provides the connection between your application
130
130
131
131
It is used to:
132
132
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)
135
135
136
136
Accordingly, the connector must implement two methods:
137
137
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.
139
139
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.
141
141
142
142
**Example**:
143
143
@@ -156,14 +156,14 @@ class MyBackendConnector extends PowerSyncBackendConnector {
// See example implementation here: https://pub.dev/documentation/powersync/latest/powersync/DevConnector/fetchCredentials.html
163
163
164
164
return {
165
165
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
Copy file name to clipboardExpand all lines: client-sdk-references/flutter/flutter-orm-support.mdx
+3-7Lines changed: 3 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,10 @@
1
1
---
2
2
title: "Flutter ORM Support (Alpha)"
3
+
sidebarTitle: "ORM Support (Alpha)"
3
4
---
4
5
6
+
An introduction to using ORMs with PowerSync is available on our blog [here](https://www.powersync.com/blog/using-orms-with-powersync).
7
+
5
8
ORM support is available via the following package (currently in an alpha release):
6
9
7
10
<Card
@@ -39,10 +42,3 @@ Every write transaction (or write statement) will lock the database for other wr
39
42
**External modifications**
40
43
41
44
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.
Copy file name to clipboardExpand all lines: client-sdk-references/flutter/flutter-web-support.mdx
+48-18Lines changed: 48 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,19 @@
1
1
---
2
-
title: "Flutter Web Support (Alpha)"
2
+
title: "Flutter Web Support (Beta)"
3
+
sidebarTitle: "Web Support (Beta)"
3
4
---
4
5
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>
6
11
7
12
## Demo app
8
13
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:
1.Clone the [powersync.dart](https://github.com/powersync-ja/powersync.dart/tree/main) repo.
12
17
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.
13
18
2. Run `melos prepare` in the repo's root
14
19
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:/
17
22
18
23
## Installing PowerSync in your own project
19
24
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:
21
26
22
27
```bash
23
-
flutter pub add powersync:'^1.6.2'
28
+
flutter pub add powersync:'^1.9.0'
24
29
```
25
30
26
-
The latest version can be found [here](https://pub.dev/packages/powersync/versions).
27
-
28
-
## Additional config
31
+
### Additional config
29
32
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.
31
35
32
36
```bash
33
37
dart run powersync:setup_web
34
38
```
35
39
36
40
The same code is used for initializing native and web `PowerSyncDatabase` clients.
37
41
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
39
75
40
76
Flutter Web does not support importing directly from `sqlite3.dart` as it uses `dart:ffi`.
in code which needs to run on the Web platform. Isolated native-specific code can still import from `sqlite3.dart`.
55
91
56
-
## Database connections
92
+
###Database connections
57
93
58
94
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.
59
95
60
96
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.
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).
#### 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.
0 commit comments