npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@electric-sql/pglite-tools

v0.2.19

Published

Tools for working with PGlite databases

Readme

pglite-tools

A selection of tools for working with PGlite databases, including pg_dump.

Install with:

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.

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 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

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};`);