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

dbml2sequelize

v1.0.8

Published

Converts [DBML](https://www.dbml.org/) files to Sequelize models.

Readme

dbml2sequelize

Converts DBML files to Sequelize models.

Table of Contents

Overview

dbml2sequelize is a Node.js library that parses .dbml files and automatically generates Sequelize models, allowing you to easily transition your database schema definitions into Sequelize-based projects.

Installation

npm install dbml2sequelize

Usage

Here's an example of how to use dbml2sequelize to convert a .dbml file into Sequelize models:

const path = require("path");
const Sequelize = require("sequelize");
const parseDbml = require("dbml2sequelize");

const opts = {
  dialect: "postgres",
  host: "localhost",
  port: 5432,
};
const sequelize = new Sequelize("micro", "admin", "password", opts);

parseDbml(sequelize, Sequelize.DataTypes, path.join(__dirname, "./db.dbml"), {
  timestamps: true,
  createdAt: "created_dt",
  updatedAt: "modified_dt",
});

sequelize.sync({ force: true }).then(() => {
  console.log("done");
});

API

parseDbml(sequelize, DataTypes, dbmlPath, options)

  • sequelize: Sequelize instance.
  • DataTypes: Sequelize DataTypes object.
  • dbmlPath: Path to the .dbml file.
  • options: (Optional) Additional model options (e.g., timestamps, createdAt, updatedAt).

Returns: Array of Sequelize models defined from the DBML file.

Example

See Usage above.

Development Guide

The main source code is in the src/ directory. The core logic is in src/index.js.

Main Flow

  1. Reading the DBML file:
    The file is read and split into definitions using grouping.js.

  2. Separating table settings:
    separating.js extracts table-level settings like indexes and notes.

  3. Parsing definitions:

    • parse-definition.js and parse-definition-type.js extract table, enum, and index structures.
    • parse-table-content.js and parse-indexes-content.js handle fields and index attributes.
  4. Converting to Sequelize Models:

    • convert-attributes.js maps DBML field types to Sequelize DataTypes.
    • convert-indexes.js and convert-note.js map DBML indexes and notes to Sequelize options.
  5. Model Generation:
    Each table definition is used to create a Sequelize model via sequelize.define.

Key Files and Responsibilities

  • src/index.js: Main entry point; orchestrates parsing and model creation.
  • src/utils/grouping.js: Groups DBML definitions.
  • src/utils/separating.js: Separates table-level settings.
  • src/parser/parse-definition.js, src/parser/parse-definition-type.js: Parse and identify DBML sections.
  • src/converter/convert-attributes.js: Converts DBML fields to Sequelize attributes.
  • src/converter/convert-indexes.js: Converts DBML indexes to Sequelize indexes.
  • src/converter/convert-note.js: Handles table/field notes.

Extending or Modifying

  • To add support for new DBML features, extend the relevant parser or converter modules.
  • To adjust Sequelize options, modify how the options object is constructed in src/index.js.

Error Handling

  • Syntax errors or unrecognized DBML specs will throw errors with details in the parser modules.
  • Ensure your .dbml files conform to DBML syntax for best results.

Contributing

Pull requests and issue reports are welcome! Please ensure code follows the style and structure of the project.

License

MIT


This documentation is generated based on the code and structure found in the repo. For more details, see the source code or open an issue.