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

db-modeling-markdown

v2.0.2

Published

database modeling markdown lib

Readme

db-modeling-markdown README

Now, you may define your database tables in markdown files, and this utility will use them to generate .sql files.

Release Notes

2.0.2

Change Log

Samples

Define a markdown file(.db.md) like:

# Table: departments

## `Table`

| `Name`      | `Comment`             | `Character Set` | `Collation`        | `Engine` |
| ----------- | --------------------- | --------------- | ------------------ | -------- |
| departments | The department table. | utf8mb4         | utf8mb4_general_ci | InnoDB   |

## `Primary Key`

| `Columns`    |
| ------------ |
| DepartmentID |

## `Indexes`

## `Foreign Keys`

| `Columns` | `Ref Table` | `Ref Columns` | `Options` |
| --------- | ----------- | ------------- | --------- |
| ManagerID | employees   | EmployeeID    |           |
| ParentID  | departments | DepartmentID  |           |

## `Columns`

| `Label`         | `Name`         | `Type`                                 | `Nullable` | `Default`           | `Comment`            |
| --------------- | -------------- | -------------------------------------- | ---------- | ------------------- | -------------------- |
| Department ID   | DepartmentID   | int auto_increment                     | `No`       |                     | Department ID        |
| Department Name | DepartmentName | varchar(50)                            | `No`       |                     | Department Name      |
| Parent ID       | ParentID       | int                                    | `Yes`      |                     | Parent Department    |
| Manager ID      | ManagerID      | int                                    | `Yes`      |                     | Manager              |
| Created By      | CreatedBy      | varchar(255)                           | `No`       | ''                  | Created By User Name |
| Create Time     | CreateTime     | datetime                               | `No`       | current_timestamp() | Created Time         |
| Update By       | UpdateBy       | varchar(255)                           | `No`       | ''                  | Updated By User Name |
| Update Time     | UpdateTime     | datetime on update current_timestamp() | `No`       | current_timestamp() | Updated Time         |

You will get SQL scripts:

-- Create table 'departments'
CREATE TABLE `departments` (
    `DepartmentID` int auto_increment NOT NULL COMMENT 'Department ID'
  , `DepartmentName` varchar(50) NOT NULL COMMENT 'Department Name'
  , `ParentID` int COMMENT 'Parent Department'
  , `ManagerID` int COMMENT 'Manager'
  , `CreatedBy` varchar(255) NOT NULL DEFAULT '' COMMENT 'Created By User Name'
  , `CreateTime` datetime NOT NULL DEFAULT current_timestamp() COMMENT 'Created Time'
  , `UpdateBy` varchar(255) NOT NULL DEFAULT '' COMMENT 'Updated By User Name'
  , `UpdateTime` datetime on update current_timestamp() NOT NULL DEFAULT current_timestamp() COMMENT 'Updated Time'
  , PRIMARY KEY (DepartmentID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='The department table.'
;

Sample Code

import * as path from 'path'

import { DatabaseTypes, DbmOptions, DbmService } from '../src'

const options: DbmOptions = new DbmOptions()
options.database = DatabaseTypes.mariadb

// Generate database modeling markdown files (.db.md) from a database
options.sourceFolder = path.join(__dirname, `../../temp/tables/v1`)
await DbmService.fromDatabase(
	{
		databaseType: options.database,
		host: '127.0.0.1',
		port: 3306,
		user: 'root',
		password: 'password',
		database: 'my-db',
	},
	options.sourceFolder,
	true,
)

// Read table definition markdow files(.db.md), and produce a sql file with create-table-if-not-exists scripts
options.sourceFolder = path.join(__dirname, '../tests/data/mariadb/tables')
options.targetPath = path.join(__dirname, '../temp/createTableIf.sql')
DbmService.toCreateTableIfNotExistsSql(options)

// Read table definition markdow files(.db.md), and produce a sql file with create-table scripts
options.targetPath = path.join(__dirname, '../temp/createTable.sql')
DbmService.toCreateTableSql(options)

// Read table definition markdow files(.db.md), and produce a sql file with drop-table scripts
options.targetPath = path.join(__dirname, '../temp/dropTable.sql')
DbmService.toDropTableSql(options)

// Read table definition markdow files(.db.md), and produce a sql file with drop-then-create-table scripts
options.targetPath = path.join(__dirname, '../temp/dropThenCreateTable.sql')
DbmService.toDropThenCreateTableSql(options)

// Read table definition markdow files(.db.md), and produce a sql file with upgrade scripts
options.previousVersionFolder = path.join(__dirname, `../tests/data/mariadb/tables/v1`)
options.targetPath = path.join(__dirname, '../temp/upgrade.sql')
DbmService.toUpgradeSql(options)

// Read table definition markdow files(.db.md), and produce a json file
options.targetPath = path.join(__dirname, '../temp/model.json')
DbmService.toJson(options)

// Read table definition markdow files(.db.md), and produce a model object
options.targetPath = ''
const model = DbmService.toModel(options)
// eslint-disable-next-line no-console
console.log(JSON.stringify(model, null, 2))

// Generate database modeling markdown files (.db.md) from a model
DbmService.toMarkdown(model, path.join(__dirname, '../temp/tables'), true)

// Generate index.md from a model
DbmService.genIndexFile(model, options.sourceFolder)

Features

  • Support Databases

    • DB2
    • MariaDB
    • MS SQL Server
    • MySQL
    • Oracle Database
    • PostgreSQL
    • SQLite
  • Support generate SQL scripts of create tables.

  • Support generate SQL scripts of create tables if not exists.

  • Support generate SQL scripts of drop then create tables.

  • Support generate SQL scripts of drop tables.

  • Support generate SQL scripts of upgrade a database (mariadb/mysql only).

  • Support generate database definition markdown files from a database (mariadb/mysql only).

  • Support generate a json file of the database model.

  • Support generate an model object of the database model.

  • Support generate database definition markdown files from a database model (json).

  • Support generate index.md for a database model.

Contributing

Please see Contributing

Enjoy!