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 🙏

© 2024 – Pkg Stats / Ryan Hefner

sequelize-erd

v1.3.1

Published

![](https://img.shields.io/github/languages/top/zekenie/sequelize-erd.svg) ![](https://img.shields.io/github/repo-size/zekenie/sequelize-erd.svg) ![](https://img.shields.io/github/issues/zekenie/sequelize-erd.svg) ![](https://img.shields.io/david/zekenie/

Downloads

13,248

Readme

Sequelize ERD

This package takes your sequelize models and produces ERD diagrams of them.

Example

It should be noted that the implimentation is a bit hacky. Its built on top of mdaines's vis.js which is described as "a hack to put Graphvis on the web." It seems like it was recently taken off NPM, so it isn't included as a dependency but instead in this package.

Installation

You don't need Graphviz or any non-javascript software to use this. Just

$ npm install sequelize-erd --save-dev

API

Exported from sequelize-erd is a function which takes your models. It can either take the sequelize instance or a path to a file to require. The function returns an svg of the models.

const {writeFileSync} = require('fs');
const Sequelize = require('sequelize');
const sequelizeErd = require('sequelize-erd');

(async function(){
  const db = new Sequelize(/* Your Sequelize config object */);
  // Import DB models here

  const svg = await sequelizeErd({ source: db }); // sequelizeErd() returns a Promise
  writeFileSync('./erd.svg', svg);

  // Writes erd.svg to local path with SVG file from your Sequelize models
})();

You can also customize the output format, engine, arrow shapes, arrow size, line colors, and line width as well as include/exclude specific models.

const svg = await sequelizeErd({
  source: db,
  format: 'json', // See available options below
  engine: 'circo',  // See available options below
  arrowShapes: {  // Any of the below 4 options formatted ['startShape', 'endShape']. If excluded, the default is used.
    BelongsToMany: ['crow', 'crow'],  // Default: ['none', 'crow']
    BelongsTo: ['inv', 'crow'], // Default: ['crow', 'none']
    HasMany: ['crow', 'inv'], // Default: ['none', 'crow']
    HasOne: ['dot', 'dot'], // Default: ['none', 'none']
  },
  arrowSize: 1.2, // Default: 0.6
  lineWidth: 1, // Default: 0.75
  color: 'green3',  // Default: 'black'
  include: ['artist', 'song', 'album', 'artistSong'],
}); // sequelizeErd() returns a Promise
writeFileSync('./erd.svg', svg);

From bash

Options

  • source relative path from project root to js file containing sequelize object with models loaded
  • destination Where you want your ERD SVG
  • include Only include the following models
  • exclude Exclude the following models
  • format File format. Options are "svg", "dot", "xdot", "plain", "plain-ext", "ps", "ps2", "json", "json0"
  • engine Layout engine to use, options are "circo", "dot", "fdp", "neato", "osage", "twopi". Default to "circo"

We expose a binary for you to use as a npm script. If you want an erd diagram generated in your project folder every time you commit, add this to your package json.

The source path specifies a js file that must export your Sequelize DB instance. It also needs to load all your models.

{
  "scripts": {
    "erd": "sequelize-erd --source ./path/to/your/sequelize/instance --destination ./erd.svg"
  }
}