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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@diegoux/schema-to-erd

v0.1.1

Published

Generates an entity-relationship diagram from a live PostgreSQL schema and emits D2 source, SVG, or Excalidraw.

Readme

Schema to ERD

Generates an entity-relationship diagram from a live PostgreSQL schema and emits D2 source, SVG, or Excalidraw.

Usage

schema-to-erd --database=postgres://user:pass@localhost/shop
schema-to-erd --tables=orders,order_items --schema=sales
schema-to-erd --tables=orders --exclude-fields='orders\.updatedAt'
schema-to-erd --types=none --output=erd.d2
schema-to-erd --tables=orders,users --output=erd.svg
schema-to-erd --output=erd.excalidraw
schema-to-erd --layout=dagre --output=erd.svg
schema-to-erd --help

The connection is specified by --database and falls back to $DATABASE_URL. --database accepts a full postgres:// or postgresql:// URL.

Output formats

| Format | Output | | ------------ | ------------------------------------------------------------------------ | | d2 | D2 source. The default. | | svg | SVG, rendered by D2's bundled WebAssembly build. No d2 install needed. | | excalidraw | Excalidraw scene, to open and keep editing in Excalidraw. |

--format sets the format. If it’s omitted, the --output extension determines the format (.d2, .svg, or .excalidraw); any other extension, or stdout, defaults to D2. If --format conflicts with the extension, it’s a usage error: --format=svg --output=erd.d2 fails rather than writing SVG to a .d2 file.

Excalidraw output uses the same layout as SVG, with tables sized for Excalidraw's hand-drawn font. Each table is a group. Element IDs are derived from table and column names, so the same schema always produces the same file, and a schema change produces a small diff.

Layout

--layout selects the engine that places tables and routes arrows: elk (the default), dagre, or tala. The tool uses a bundled D2 in WebAssembly. If you specify a layout for a D2 output, the .d2 file will include a config block that sets the layout (you can override it via the d2 CLI).

If you need to refine the output style, use d2.

The default layout is elk because it’s slightly faster with the bundled WebAssembly d2 package. However, in many cases, tala will produce better results.

Options

| Flag | Meaning | | ------------------------------ | ---------------------------------------------- | | --database=<url> | Connection URL. Defaults to $DATABASE_URL. | | --tables=a,b | Only these tables. Omit for the whole schema. | | --schema=<name> | Schema to read. Default public. | | --types=none\|base\|full | Type detail. Default base. | | --hide-types | Alias for --types=none. | | --no-nullable-markers | Drop the ? suffix on nullable columns. | | --exclude-fields=<re> | Drop matching columns. Repeatable. | | --format=d2\|svg\|excalidraw | Output format. Default from --output, or d2. | | --layout=elk\|dagre\|tala | Layout engine. Default elk. | | --output=<path> | Write to a file instead of stdout. Overwrites. | | -h, --help | Show help. |

Type detail

| Mode | email renders as | | ------ | ----------------------------------- | | none | "email" | | base | "email": "varchar" | | full | "email": "character varying(255)" |

Excluding fields

--exclude-fields takes a regular expression that is matched unanchored and case-sensitively against the schema.table.field path:

# every updatedAt column
--exclude-fields='updatedAt'

# only orders.updatedAt
--exclude-fields='orders\.updatedAt'

Exit codes

| Code | Meaning | | ---- | ----------------------------------------------------------------------------------------------------- | | 0 | Success, and --help. | | 1 | Runtime failure: a table in --tables does not exist, the schema is empty, or the connection failed. | | 2 | Usage error. Prints help to stderr. |

Install

schema-to-erd runs on Node.js 22 or later. However, the project uses Bun for development:

bun install
bun run build
bun link

bun run build bundles it into dist/ with bunup, and bun link puts schema-to-erd on your PATH. Without it, run node dist/schema-to-erd.js with the same arguments, or skip the build and run bun run src/schema-to-erd.ts.

Tests

bun test           # unit + integration; needs Docker
bun run test:unit  # unit only, no Docker

Both also pack the package and run its binary on the Node.js on your PATH, checking it against the source run on Bun. Without Node.js, those tests are skipped.

License

MIT