Skip to content
Skillv1.0.0

pglite

You are an expert in PGlite, the lightweight WASM Postgres build that runs in the browser, Node.js, and Deno. You help developers embed a full Postgres instance (with extensions like pgvector, PostGIS

by terminalskills(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from terminalskills/skills (skills/pglite/SKILL.md). Install upstream with npx skills add terminalskills/skills --skill pglite. Copyright stays with the author (Apache-2.0).

PGlite — Postgres in the Browser

You are an expert in PGlite, the lightweight WASM Postgres build that runs in the browser, Node.js, and Deno. You help developers embed a full Postgres instance (with extensions like pgvector, PostGIS) in client-side apps, Electron, React Native, and serverless functions — providing real SQL with JSONB, full-text search, and vector similarity search at ~3MB compressed, without a server.

Core Capabilities

Browser Usage

import { PGlite } from "@electric-sql/pglite";
import { vector } from "@electric-sql/pglite/vector";

// Create in-memory database
const db = new PGlite({
  extensions: { vector },
});

// Or persist to IndexedDB
const db = new PGlite({
  dataDir: "idb://my-app-db",
  extensions: { vector },
});

// Full Postgres SQL
await db.exec(`
  CREATE TABLE IF NOT EXISTS documents (
    id SERIAL PRIMARY KEY,
    title TEXT NOT NULL,
    content TEXT,
    embedding vector(384),
    metadata JSONB DEFAULT '{}',
    created_at TIMESTAMPTZ DEFAULT NOW()
  );

  CREATE INDEX ON documents USING ivfflat (embedding vector_cosine_ops) WITH (lists = 100);
  CREATE INDEX ON documents USING GIN (metadata);
  CREATE INDEX ON documents USING GIN (to_tsvector('english', title || ' ' || content));
`);

// Insert
await db.query(
  `INSERT INTO documents (title, content, embedding, metadata) VALUES ($1, $2, $3, $4)`,
  ["Getting Started", "Welcome to PGlite...", embedding, JSON.stringify({ category: "tutorial" })],
);

// Full-text search
const results = await db.query(`
  SELECT title, ts_rank(to_tsvector('english', content), query) AS rank
  FROM documents, plainto_tsquery('english', $1) query
  WHERE to_tsvector('english', content) @@ query
  ORDER BY rank DESC LIMIT 10
`, ["postgres wasm"]);

// Vector similarity search
const similar = await db.query(`
  SELECT title, 1 - (embedding <=> $1::vector) AS similarity
  FROM documents
  ORDER BY embedding <=> $1::vector
  LIMIT 5
`, [queryEmbedding]);

// JSONB queries
const tutorials = await db.query(`
  SELECT * FROM documents WHERE metadata->>'category' = $1
`, ["tutorial"]);

Live Queries (Reactive)

import { live } from "@electric-sql/pglite/live";

const db = new PGlite({ extensions: { live } });

// Subscribe to query results — re-runs when data changes
const unsubscribe = await db.live.query(
  `SELECT * FROM documents WHERE metadata->>'category' = $1 ORDER BY created_at DESC`,
  ["tutorial"],
  (results) => {
    console.log("Documents updated:", results.rows);
    // Re-renders your UI automatically
  },
);

// React hook
import { useLiveQuery } from "@electric-sql/pglite-react";

function DocumentList({ category }: { category: string }) {
  const docs = useLiveQuery(
    `SELECT * FROM documents WHERE metadata->>'category' = $1`,
    [category],
  );
  return <ul>{docs?.rows.map(d => <li key={d.id}>{d.title}</li>)}</ul>;
}

Installation

npm install @electric-sql/pglite

Best Practices

  1. Full Postgres — Not a subset; real Postgres with JSONB, CTEs, window functions, extensions
  2. IndexedDB persistence — Use idb:// prefix for data directory; survives page refreshes
  3. pgvector — Vector search in the browser; run RAG locally without a server
  4. Live queries — Subscribe to query results; automatic re-execution when underlying data changes
  5. 3MB compressed — Small enough for browser apps; loads in <1 second
  6. Drizzle/Prisma — Use with Drizzle ORM for type-safe queries; PGlite driver available
  7. Testing — Use PGlite in tests instead of Docker Postgres; instant setup, zero cleanup
  8. Local-first — Pair with Electric SQL for sync; local PGlite + cloud Postgres

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/terminalskills-skills-pglite/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

terminalskills-skills-pglite.ocm.jsonjson
{
  "ocm": "1",
  "id": "terminalskills-skills-pglite",
  "kind": "skill",
  "name": "pglite",
  "description": "You are an expert in PGlite, the lightweight WASM Postgres build that runs in the browser, Node.js, and Deno. You help developers embed a full Postgres instance (with extensions like pgvector, PostGIS) in client-side apps, Electron, React Native, and serverless functions — providing real SQL with JSONB, full-text search, and vector similarity search at ~3MB compressed, without a server.",
  "publisher": "terminalskills",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding",
      "data_analysis"
    ],
    "tags": [
      "skill-md",
      "postgres",
      "wasm",
      "browser",
      "embedded",
      "local-first",
      "database",
      "lightweight",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "You are an expert in PGlite, the lightweight WASM Postgres build that runs in the browser, Node.js, and Deno. You help developers embed a full Postgres instance (with extensions like pgvector, PostGIS) in client-side apps, Electron, React Native, and serverless functions — providing real SQL with JSONB, full-text search, and vector similarity search at ~3MB compressed, without a server."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/terminalskills/skills",
      "path": "skills/pglite/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/terminalskills/skills/blob/HEAD/skills/pglite/SKILL.md",
      "key": "terminalskills/skills/skills/pglite/SKILL.md"
    },
    "license": "Apache-2.0"
  },
  "instructions": "# PGlite — Postgres in the Browser\n\nYou are an expert in PGlite, the lightweight WASM Postgres build that runs in the browser, Node.js, and Deno. You help developers embed a full Postgres instance (with extensions like pgvector, PostGIS) in client-side apps, Electron, React Native, and serverless functions — providing real SQL with JSONB, full-text search, and vector similarity search at ~3MB compressed, without a server.\n\n## Core Capabilities\n\n### Browser Usage\n\n```typescript\nimport { PGlite } from \"@electric-sql/pglite\";\nimport { vector } from \"@electric-sql/pglite/vector\";\n\n// Create in-mem",
  "cost": {
    "context_tokens": 926
  }
}

Fetch it by URL: GET /api/v1/registry/terminalskills-skills-pglite/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.