@electric-sql/pglite-sync
TypeScript icon, indicating that this package has built-in type declarations

0.2.9 • Public • Published

PGlite ElectricSQL Sync Plugin

A sync plugin for PGlite using ElectricSQL. Full documentation is available at pglite.dev/docs/sync.

To install:

npm install @electric-sql/pglite-sync

Then add it to you PGlite instance and create any local tables needed:

import { electricSync } from '@electric-sql/pglite-sync'

const pg = await PGlite.create({
  extensions: {
    electric: electricSync(),
  },
})

await pg.exec(`
  CREATE TABLE IF NOT EXISTS todo (
    id SERIAL PRIMARY KEY,
    task TEXT,
    done BOOLEAN
  );
`)

You can then use the syncShapeToTable method to sync a table from Electric:

const shape = await pg.electric.syncShapeToTable({
  url: 'http://localhost:3000/v1/shape/todo',
  table: 'todo',
  primaryKey: ['id'],
})

Package Sidebar

Install

npm i @electric-sql/pglite-sync

Homepage

pglite.dev

Weekly Downloads

186

Version

0.2.9

License

Apache-2.0

Unpacked Size

59.5 kB

Total Files

9

Last publish

Collaborators

  • sgwillis
  • icehaunter
  • thruflo