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
description: 'RxDB (Reactive Database) is a local-first, NoSQL database for JavaScript applications.'
15
+
platform:
16
+
- 'Self-hosted'
17
+
- 'Cloud'
18
+
images:
19
+
- /images/integrations/replication-rxdb/cover.png
20
+
---
21
+
22
+
RxDB (Reactive Database) is a client-side, NoSQL database designed for JavaScript applications. It emphasizes real-time data synchronization, offline-first capabilities, and reactive programming paradigms. RxDB is particularly suited for applications that require seamless user experiences across various platforms, including web browsers, mobile devices, and desktop environments.
23
+
24
+
# How does the integration work?
25
+
26
+
RxDB integrates with Appwrite through a replication plugin that enables two-way data synchronization between a client-side RxDB instance and an Appwrite Database. This setup allows apps to store data locally (using data stores such as LocalStorage, SQLite, or IndexedDB) and push/pull changes from the Appwrite backend. When offline, the app continues to function smoothly using RxDB's local-first model, and once connectivity is restored, it syncs changes with Appwrite. Conflict handling, soft deletion, and live replication are handled seamlessly using RxDB’s built-in tools and Appwrite’s Realtime API.
27
+
28
+
# How to implement
29
+
30
+
To implement the RxDB integration, there are several steps you must complete:
31
+
32
+
## Step 1: Configure Appwrite project
33
+
34
+
For this step, you must [create an account on Appwrite Cloud](https://cloud.appwrite.io/register) or [self-host Appwrite](https://appwrite.io/docs/advanced/self-hosting) if you haven’t already. Head over to the Appwrite console, go to the **Settings** page, and copy your project ID and API endpoint for further usage. Next, go to the **Databases** page from the left sidebar, create a new database with the ID `mydb`, and then a collection with the ID `humans` (save both IDs for further usage).
35
+
36
+
Click on the **Attributes** tab and add the following attributes (schema used for demo purposes):
37
+
38
+
| Key | Type | Size | Required |
39
+
| --- | --- | --- | --- |
40
+
| `name` | String | 100 | Yes |
41
+
| `age` | Integer | | Yes |
42
+
| `homeAddress` | String | 2000 | Yes |
43
+
| `deleted` | Boolean | | Yes |
44
+
45
+
> **Note:** The `deleted` attribute is necessary to add because RxDB only soft deletes to prevent data loss in offline scenarios (no hard deletion of data occurs).
46
+
47
+
Then, head to the **Settings** tab of your collection, scroll down to the **Permissions** section, and the following:
48
+
49
+
| Role | Create | Read | Update | Delete |
50
+
| --- | --- | --- | --- | --- |
51
+
| Any | Yes | Yes | Yes | Yes |
52
+
53
+
> **Note:** While RxDB does not allow you to manually configure permissions for each document, if your app uses Appwrite Auth and document-level permissions are enabled for your collection, the Appwrite SDK will automatically assign read and write permissions to the logged-in user for each document created.
54
+
55
+
## Step 2: Install Appwrite Web SDK and RxDB library
56
+
57
+
Open the terminal in your app’s working directory and run the following command:
58
+
59
+
```bash
60
+
npm install appwrite rxdb
61
+
```
62
+
63
+
In your app’s `.env` file, add the following:
64
+
65
+
```bash
66
+
APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1
67
+
APPWRITE_PROJECT_ID=your-project-id
68
+
APPWRITE_DATABASE_ID=your-database-id
69
+
APPWRITE_COLLECTION_ID=your-collection-id
70
+
```
71
+
72
+
Then, import all necessary libraries in your code:
73
+
74
+
```js
75
+
import { replicateAppwrite } from 'rxdb/plugins/replication-appwrite';
76
+
import { createRxDatabase, addRxPlugin, RxCollection } from 'rxdb/plugins/core';
77
+
import { getRxStorageLocalstorage } from 'rxdb/plugins/storage-localstorage';
78
+
import { Client } from 'appwrite';
79
+
```
80
+
81
+
## Step 3: Setup Appwrite client
82
+
83
+
To create an Appwrite client, add the following code:
0 commit comments