Skip to content

Plugin for RxDB that allows you to use PgLite as a storage engine.

License

Notifications You must be signed in to change notification settings

XuHaoJun/rxdb-storage-pglite

Repository files navigation

RxDB PgLite

This is a plugin for RxDB that allows you to use PGLite as a storage engine.

Most of the code is generated by cursor, still working in progress. need more test.

Installation

npm install @xuhaojun/rxdb-storage-pglite @electric-sql/pglite

Usage

import { getRxStoragePGLite } from "@xuhaojun/rxdb-storage-pglite";

// nodejs with local file storage
const myDatabase = await createRxDatabase<YourCollections>({
    name: "test",
    storage: getRxStoragePGLite({ path: path.join(__dirname, "test.db") }),
});

// browser with indexedDB storage
const myDatabase = await createRxDatabase<YourCollections>({
    name: "test",
    storage: getRxStoragePGLite({ path: "idb://test" }),
});

// expo with expo-file-system
import * as FileSystem from "expo-file-system";
const myDatabase = await createRxDatabase<YourCollections>({
    name: "test",
    storage: getRxStoragePGLite({
        path: FileSystem.documentDirectory + "test.db",
    }),
});

How it works

Create a SQL Table for each collection.

CREATE TABLE your_collection_name (
    id TEXT PRIMARY KEY,
    data JSONB NOT NULL DEFAULT '{}'
);

The data column is a JSONB column that stores the document data.

Translate the RxDB query to the SQL query by mongo-query-to-postgres-jsonb

About

Plugin for RxDB that allows you to use PgLite as a storage engine.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published