PowerSync keeps a client-side SQLite database in sync with your backend database. Changes appear across users and devices in real-time, user interactions feel instant and your app continues to work even when offline. Supports Postgres, MongoDB, MySQL, and SQL Server. Client SDKs are available for a wide range of environments including web, mobile, desktop, headless and embedded.
This package (packages/web) is the PowerSync SDK for JavaScript Web clients. It is an extension of packages/common.
See a summary of features here.
npm install @powersync/webTo enable encryption you need to specify an encryption key when instantiating the PowerSync database.
The PowerSync Web SDK uses the ChaCha20 cipher algorithm by default.
export const db = new PowerSyncDatabase({
// The schema you defined
schema: AppSchema,
database: {
// Filename for the SQLite database — it's important to only instantiate one instance per file.
dbFilename: 'example.db'
// Optional. Directory where the database file is located.'
// dbLocation: 'path/to/directory'
},
// Encryption key for the database.
encryptionKey: 'your-encryption-key'
});
// If you are using a custom WASQLiteOpenFactory or WASQLiteDBAdapter, you need specify the encryption key inside the construtor
export const db = new PowerSyncDatabase({
schema: AppSchema,
database: new WASQLiteOpenFactory({
//new WASQLiteDBAdapter
dbFilename: 'example.db',
vfs: WASQLiteVFS.OPFSCoopSyncVFS,
// Encryption key for the database.
encryptionKey: 'your-encryption-key'
})
});See the example Webpack config for details on polyfills and requirements.
See the example Vite config for details on polyfills and requirements.
Our full SDK reference contains everything you need to know to get started implementing PowerSync in your project.
For some frameworks, it may be required to configure the web workers (see the docs).
The @powersync/web package includes a CLI utility which can copy the required assets to the public directory (configurable with the --output option).
pnpm powersync-web copy-assetsA changelog for this SDK is available here.
The full API reference for this SDK can be found here.
For example projects built with PowerSync on Web, see our Demo Apps / Example Projects gallery. Most of these projects can also be found in the demos/ directory.
- Join our Discord server where you can browse topics from our community, ask questions, share feedback, or just say hello :)
- Please open a GitHub issue when you come across a bug.
- Have feedback or an idea? Submit an idea via our public roadmap or schedule a chat with someone from our product team.
