https://github.com/electric-sql/pglite Skip to content Toggle navigation Sign in * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Resources + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} electric-sql / pglite Public * Notifications * Fork 9 * Star 585 * PGlite - Postgres in WASM electric-sql.com 585 stars 9 forks Branches Tags Activity Star Notifications * Code * Issues 7 * Pull requests 0 * Actions * Security * Insights Additional navigation options * Code * Issues * Pull requests * Actions * Security * Insights electric-sql/pglite This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main BranchesTags Go to file Code Folders and files Name Name Last commit Last commit message date Latest commit History 9 Commits packages/pglite packages/pglite postgres @ cf202fd postgres @ cf202fd .gitignore .gitignore .gitmodules .gitmodules README.md README.md pnpm-lock.yaml pnpm-lock.yaml pnpm-workspace.yaml pnpm-workspace.yaml screenshot.png screenshot.png View all files Repository files navigation * README PGlite - Postgres in WASM PGlite PGlite is a WASM Postgres build packaged into a TypeScript client library that enables you to run Postgres in the browser, Node.js and Bun, with no need to install any other dependencies. It is only 3.7mb gzipped. import { PGlite } from "@electric-sql/pglite" const db = new PGlite() await db.query("select 'Hello world' as message;") // -> [ { message: "Hello world" } ] It can be used both as an ephemeral in-memory database or with persistance to the file system (Node/Bun) or indexedDB (Browser). Unlike previous "Postgres in the browser" projects, PGlite does not use a Linux virtual machine - it is simply Postgres in WASM. It is being developed at ElectricSQL in collaboration with Neon. We plan to continue to build on this experiment, and aim to create a fully capable lightweight WASM Postgres with support for extensions such as pgvector. Node/Bun Install into your project: npm install @electric-sql/pglite To use the in-memory Postgres: import { PGlite } from "@electric-sql/pglite" const db = new PGlite() await db.query("select 'Hello world' as message;") // -> [ { message: "Hello world" } ] or to persist to the filesystem: const db = new PGlite('./path/to/pgdata') Browser It can be loaded via JSDeliver or your usual package manager, and for an in-memory Postgres: or to persist the database to indexedDB: const db = new PGlite('idb://my-pgdata') Deno To use the in-memory Postgres, create a file server.ts: import { PGlite } from "npm:@electric-sql/pglite" Deno.serve(async (_request: Request) => { const db = new PGlite() const query = await db.query("select 'Hello world' as message;") return new Response(JSON.stringify(query)) }) Then run the file with deno run --allow-net --allow-read server.ts. Limitations Parameterized queries are not currently supported, but this will be added soon. Building There are a couple of prerequisites: * the Postgres build toolchain * emscripten version 3.1.25 To build, checkout the repo, then: cd ./pglite/packages/pglite emsdk install 3.1.25 emsdk activate 3.1.25 pnpm install pnpm build Acknowledgments PGlite builds on the work of Stas Kelvich of Neon in this Postgres fork. About PGlite - Postgres in WASM electric-sql.com Resources Readme Activity Custom properties Stars 585 stars Watchers 12 watching Forks 9 forks Report repository Releases No releases published Packages 0 No packages published Contributors 4 * * * * Languages * TypeScript 72.6% * JavaScript 13.8% * HTML 7.8% * Makefile 5.8% Footer (c) 2024 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact * Manage cookies * Do not share my personal information You can't perform that action at this time.