pglite
БесплатноБез исполняемых скриптовНе проверенPGlite is Postgres compiled to WebAssembly: a real Postgres 18 database that runs inside the browser, Node.js, Bun or Deno with no server, in-memory or…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
PGlite — Postgres in the Browser
Overview
PGlite (by ElectricSQL) is a WebAssembly build of Postgres packaged as a TypeScript library. It runs as a single connection inside your process: real Postgres SQL (JSONB, CTEs, window functions, full-text search, triggers) with no daemon and no Docker. As of 0.5.x it is PostgreSQL 18; select version() reports it.
Where it fits: local-first and offline apps, Electron, tests and CI that need real Postgres semantics, prototypes, in-browser RAG with pgvector. It is not a server replacement: one connection, one process (use the multi-tab worker or @electric-sql/pglite-socket to share it).
0.5 changes that break older snippets: most extensions moved to their own packages. pgvector is now @electric-sql/pglite-pgvector (import { vector } from "@electric-sql/pglite-pgvector"), not @electric-sql/pglite/vector; PostGIS, AGE, pgtap, pgmq and others are @electric-sql/pglite-postgis, -age and so on. live and the Postgres contrib extensions (@electric-sql/pglite/contrib/<name>, e.g. pg_trgm, hstore, citext) stay in the main package. Extension packages pin the exact PGlite version they were built for, so keep versions in step.
Instructions
Install and open a database
npm install @electric-sql/pglite
import { PGlite } from "@electric-sql/pglite";
const memory = new PGlite(); // in-memory, lost on exit
const browser = new PGlite("idb://notes-app"); // IndexedDB (recommended in browsers)
const server = await PGlite.create("./pgdata"); // folder on disk in Node/Bun (parent folder must exist)
await server.waitReady;
PGlite.create(...) resolves when the database is ready; with new PGlite(...) await db.waitReady or just start querying. OPFS-backed storage (@electric-sql/pglite/opfs-ahp) exists but Safari does not support it, so the docs recommend IndexedDB in browsers. Call await db.close() before exiting a Node process.
Query
await db.exec(`
CREATE TABLE IF NOT EXISTS notes (
id SERIAL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT,
meta JSONB DEFAULT '{}',
created_at TIMESTAMPTZ DEFAULT now()
);
CREATE INDEX IF NOT EXISTS notes_fts ON notes
USING GIN (to_tsvector('english', coalesce(title,'') || ' ' || coalesce(body,'')));
`); // exec: many statements, no parameters
const { rows } = await db.query( // query: one statement, $1 parameters
"SELECT id, title FROM notes WHERE meta->>'tag' = $1 ORDER BY created_at DESC",
["tutorial"],
);
await db.transaction(async (tx) => {
await tx.query("INSERT INTO notes (title) VALUES ($1)", ["Draft"]);
});
Pass a type to get typed rows: db.query<{ id: number; title: string }>(...). Pass JSON as an object or JSON.stringify(...) for JSONB parameters.
pgvector
npm install @electric-sql/pglite-pgvector
import { PGlite } from "@electric-sql/pglite";
import { vector } from "@electric-sql/pglite-pgvector";
const db = await PGlite.create({ extensions: { vector } });
await db.exec(`
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE IF NOT EXISTS chunks (id SERIAL PRIMARY KEY, text TEXT, embedding vector(384));
CREATE INDEX IF NOT EXISTS chunks_hnsw ON chunks USING hnsw (embedding vector_cosine_ops);
`);
await db.query("INSERT INTO chunks (text, embedding) VALUES ($1, $2)", ["hello", JSON.stringify(vec)]);
const hits = await db.query(
"SELECT text, 1 - (embedding <=> $1::vector) AS similarity FROM chunks ORDER BY embedding <=> $1::vector LIMIT 5",
[JSON.stringify(queryVec)],
);
The CREATE EXTENSION statement is required even after passing the extension object. Vectors are passed as '[0.1,0.2,...]' text.
Live queries
import { live } from "@electric-sql/pglite/live";
const db = await PGlite.create({ extensions: { live } });
const sub = await db.live.query("SELECT * FROM notes ORDER BY id DESC", [], (res) => {
console.log(res.rows); // called now and after every change
});
await sub.unsubscribe(); // always release it
Use db.live.incrementalQuery for large or wide result sets (diffed inside Postgres) and db.live.changes for raw insert/update/delete events. React: npm install @electric-sql/pglite-react, wrap the app in <PGliteProvider db={db}>, and call useLiveQuery("SELECT ...", [params]); it returns undefined until the first result arrives, then { rows, fields }.
Worker, tools, upgrades
- Do not block the UI thread / share across tabs:
PGliteWorkerfrom@electric-sql/pglite/workerwith a worker file that callsworker({ async init() { return new PGlite("idb://notes-app") } }); one tab is elected leader. - ORMs:
drizzle-orm/pglite(drizzle(client)) works directly; Prisma uses PGlite behindnpx prisma dev. - Backups: `await db.d
Установить pglite в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл pglite?
PGlite is Postgres compiled to WebAssembly: a real Postgres 18 database that runs inside the browser, Node.js, Bun or Deno with no server, in-memory or persisted to IndexedDB or a folder. Use when someone asks to "run Postgres in the browser", "embed Postgres in an app", "use PGlite", "local-first database", "Postgres for tests without Docker", or "vector search in the browser". Covers install, persistence, pgvector, live queries, workers, and upgrades between versions.
Как установить скилл pglite?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл pglite запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic