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.
npm install @xuhaojun/rxdb-storage-pglite @electric-sql/pglite
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",
}),
});
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