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
This example shows how the [PowerSync Node.js client](https://docs.powersync.com/client-sdk-references/node#node-js-client-alpha) can be used in the main process of an Electron app.
4
+
5
+
The purpose of this example is to highlight specific build configurations that enable this setup.
6
+
In particular:
7
+
8
+
1. In `src/main/index.ts`, a `PowerSyncDatabase` is created. PowerSync uses node workers to speed up database
9
+
queries. This worker is part of the `@powersync/node` package and wouldn't be copied into the resulting Electron
10
+
app by default. For this reason, this example has its own `src/main/worker.ts` loaded with `new URL('./worker.ts', import.meta.url)`.
11
+
2. In addition to the worker, PowerSync requires access to a SQLite extension providing sync functionality.
12
+
This file is also part of the `@powersync/node` package and called `powersync.dll`, `libpowersync.dylib` or
13
+
`libpowersync.so` depending on the operating system.
14
+
We use the `copy-webpack-plugin` package to make sure a copy of that file is available to the main process,
15
+
and load it in the custom `src/main/worker.ts`.
16
+
3. The `get()` and `getAll()` methods are exposed to the renderer process with an IPC channel.
17
+
18
+
To see it in action:
19
+
20
+
1. Make sure to run `pnpm install` and `pnpm build:packages` in the root directory of this repo.
21
+
2. Copy `.env.local.template` to `.env.local`, and complete the environment variables. You can generate a [temporary development token](https://docs.powersync.com/usage/installation/authentication-setup/development-tokens), or leave blank to test with local-only data.
22
+
The example works with the schema from the [PowerSync + Supabase tutorial](https://docs.powersync.com/integration-guides/supabase-+-powersync#supabase-powersync).
23
+
3.`cd` in this directory and run `pnpm start`.
24
+
25
+
Apart from the build setup, this example is purposefully kept simple.
26
+
To make sure PowerSync is working, you can run `await powersync.get('SELECT powersync_rs_version()');` in the DevTools
27
+
console. A result from that query implies that the PowerSync was properly configured.
28
+
29
+
For more details, see the documentation for [the PowerSync node package](https://docs.powersync.com/client-sdk-references/node#node-js-client-alpha) and check other examples:
30
+
31
+
-[example-node](../example-node/): A Node.js CLI example that connects to PowerSync to run auto-updating queries.
32
+
-[example-electron](../example-electron/): An Electron example that runs PowerSync in the render process instead of in the main one.
0 commit comments