# @electric-sql/pglite-tools

> Tools for working with PGlite databases

Latest version **0.4.8** (published 2026-08-26) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @electric-sql/pglite-tools
pnpm add @electric-sql/pglite-tools
yarn add @electric-sql/pglite-tools
bun add @electric-sql/pglite-tools
```

## Health

**Score 80/100 (A)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score; popular repo.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.4.8 |
| Published | 2026-08-26 |
| First published | 2024-11-26 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 1.7 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 16018 |
| Author | Electric DB Limited |
| Maintainers | thruflo, icehaunter, kylemathews, sgwillis |
| Keywords | postgres, sql, database, wasm, pglite, pg_dump, pg_restore |

## Links

- npm: https://www.npmjs.com/package/@electric-sql/pglite-tools
- Repository: https://github.com/electric-sql/pglite
- Homepage: https://pglite.dev
- Issues: https://github.com/electric-sql/pglite/issues
- npm.io page: https://npm.io/package/@electric-sql/pglite-tools

## Alternatives

- [@libsql/sqlite3](https://npm.io/package/@libsql/sqlite3.md) — 39.8K weekly downloads
- [@fortemi/core](https://npm.io/package/@fortemi/core.md) — 461 weekly downloads
- [cdb-converter](https://npm.io/package/cdb-converter.md) — 341 weekly downloads
- [@uplo/adapter-prisma](https://npm.io/package/@uplo/adapter-prisma.md) — 75 weekly downloads
- [typeorm-aios](https://npm.io/package/typeorm-aios.md) — 30 weekly downloads

## Recent versions

- 0.4.8 (latest) — 2026-08-26
- 0.4.7 — 2026-08-23
- 0.4.6 — 2026-08-22
- 0.4.5 — 2026-08-13
- 0.4.4 — 2026-07-02
- 0.4.3 — 2026-06-16
- 0.4.2 — 2026-06-11
- 0.4.1 — 2026-06-02
- 0.4.0 — 2026-06-02
- 0.3.6 — 2026-05-25
- 0.3.5 — 2026-04-27
- 0.3.4 — 2026-04-09
- 0.3.3 — 2026-04-02
- 0.3.2 — 2026-03-25
- 0.3.1 — 2026-03-19
- … 22 more at https://npm.io/package/@electric-sql/pglite-tools/versions

## README

# pglite-tools

A selection of tools for working with [PGlite](https://github.com/electric-sql/pglite) databases, including pg_dump.

Install with:

```bash
npm install @electric-sql/pglite-tools
```

## `pgDump`

pg_dump is a tool for dumping a PGlite database to a SQL file, this is a WASM build of pg_dump that can be used in a browser or other JavaScript environments. You can read more about pg_dump [in the Postgres docs](https://www.postgresql.org/docs/current/app-pgdump.html).

Note: pg_dump will execute `DEALLOCATE ALL;` after each dump. Since this is running on the same (single) connection, any prepared statements that you have made before running pg_dump will be affected.

### Options

- `pg`: A PGlite instance.
- `args`: An array of arguments to pass to pg_dump - see [pg_dump docs](https://www.postgresql.org/docs/current/app-pgdump.html) for more details.
- `fileName`: The name of the file to write the dump to, defaults to `dump.sql`.

There are a number of arguments that are automatically added to the end of the command, these are:

- `--inserts` - use inserts format for the output, this ensures that the dump can be restored by simply passing the output to `pg.exec()`.
- `-j 1` - concurrency level, set to 1 as multithreading isn't supported.
- `-f /tmp/out.sql` - the output file is always written to `/tmp/out.sql` in the virtual file system.
- `-U postgres` - use the postgres user is hard coded.

### Returns

- A `File` object containing the dump.

### Caveats

- After restoring a dump, you might want to set the same search path as the initial db.

### Example

```typescript
import { PGlite } from '@electric-sql/pglite'
import { pgDump } from '@electric-sql/pglite-tools/pg_dump'

const pg = await PGlite.create()

// Create a table and insert some data
await pg.exec(`
  CREATE TABLE test (
    id SERIAL PRIMARY KEY,
    name TEXT
  );
`)
await pg.exec(`
  INSERT INTO test (name) VALUES ('test');
`)

// store the current search path so it can be used in the restored db
const initialSearchPath = (await pg1.query<{ search_path: string }>('SHOW SEARCH_PATH;')).rows[0].search_path

// Dump the database to a file
const dump = await pgDump({ pg })
// Get the dump text - used for restore
const dumpContent = await dump.text()

// Create a new database 
const restoredPG = await PGlite.create()
// ... and restore it using the dump
await restoredPG.exec(dumpContent)

// optional - after importing, set search path back to the initial one
await restoredPG.exec(`SET search_path TO ${initialSearchPath};`);
```

---
_Source: https://npm.io/package/@electric-sql/pglite-tools · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
