pg-lite-promise
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

pg-promise adapter for pg-lite

This library provides seamless integration between the ultra-fast, WebAssembly-based PostgreSQL distribution pg-lite and the popular PostgreSQL interface pg-promise.
Its implementation is heavily inspired by the pg-promise adapter from the pg-mem project.

Installation

Install via npm:

npm i pg-lite-promise

Or via yarn:

yarn add pg-lite-promise

Getting started

Import and initialize a pg-lite database instance, then bind it to pg-promise:

import { PGlite } from "@electric-sql/pglite";
import { buildPgLitePromiseClient } from "pg-lite-promise";

// Initialize pg-lite database
const db = new PGlite();

// Wrap pg-lite instance with pg-promise interface
const pgpLite = buildPgLitePromiseClient(db);

Optional Configuration

The buildPgLitePromiseClient function accepts an optional second parameter of type pgPromise.IInitOptions & { queryLatency?: number }. You can use this to simulate query latency:

// Introduce artificial latency of 100ms
const pgpLite = buildPgLitePromiseClient(db, { queryLatency: 100 });

Example usage

import { PGlite } from "@electric-sql/pglite";
import { buildPgLitePromiseClient } from "pg-lite-promise";

const main = async () => {
  // Initialize pg-lite database
  const db = new PGlite();
  await db.exec(`
    create table data(id text primary key, data jsonb, num integer, var varchar(10));
    insert into data values ('str', '{"data": true}', 42, 'varchar')
  `);

  // Wrap pg-lite instance with pg-promise interface
  const pgpLite = buildPgLitePromiseClient(db);

  // Use pg-promise api 
  const result = await pgpLite.any("select * from data");
  console.log(result);
}
main();

Further Documentation

Readme

Keywords

Package Sidebar

Install

npm i pg-lite-promise

Weekly Downloads

5

Version

0.0.1

License

ISC

Unpacked Size

9.93 kB

Total Files

7

Last publish

Collaborators

  • alexvictoor