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

generathor-db

v2.0.0

Published

Use this to get database info

Readme

Generathor-DB

Generathor-DB is a powerful introspection engine that retrieves the structure of your database (MySQL and PostgreSQL) and standardizes it into a consistent format.

Designed to work seamlessly with Generathor, it enables automatic generation of models, controllers, migrations, and more, by providing a high-level abstraction of your database schema.

Features

  • 🔍 Introspection: Deeply scans tables, columns, indexes, primary keys, and relations.
  • 🐘 PostgreSQL & 🐬 MySQL Support: Built-in support for the most popular relational databases.
  • 🔧 Transformers: Modify and enrich the scanned data before handing it over to your generators.

Installation

npm install generathor-db

[!IMPORTANT] Since drivers are lazy-loaded, you must install the driver for your database manually:

  • For MySQL: npm install mysql2
  • For PostgreSQL: npm install pg

Usage

Simple Example (MySQL)

import { Source } from 'generathor-db';

const source = new Source({
  type: 'mysql',
  configuration: {
    host: 'localhost',
    port: 3306,
    user: 'root',
    password: 'password',
    database: 'my_app'
  }
});

PostgreSQL with Transformers

import { Source } from 'generathor-db';

const source = new Source({
  type: 'postgresql',
  configuration: {
    host: 'localhost',
    port: 5432,
    user: 'postgres',
    password: 'password',
    database: 'my_app',
    schema: 'public' // Optional, defaults to 'public'
  }
}, [
  (item) => {
    // Add custom metadata for your generators
    item.className = item.table.charAt(0).toUpperCase() + item.table.slice(1);
  }
]);

API Documentation

Source

The constructor accepts the following parameters:

| Parameter | Type | Required | Description | |-------------------------|-----------------|----------|--------------------------------------------------| | sourceConfiguration | EngineInput | Yes | Connection and configuration options. | | transformers | Transformer[] | No | Array of functions to modify items after scanning. |

Transformer

A simple callback used to modify or enrich an Item before it is consumed.

type Transformer = (item: Item) => void;

Engine Configurations

Engine Input

The sourceConfiguration (or EngineInput in TypeScript) defines which database to scan and how to connect to it.

| Field | Type | Required | Description | |-----------------|----------------------------------------------------|----------|------------------------------------------------| | type | 'mysql' | 'postgresql' | Yes | The database engine type. | | configuration | MySQLConfiguration | PostgreSQLConfiguration | Yes | Engine-specific connection details. | | excludes | string[] | No | List of table names to ignore during scanning. |

MySQL Configuration

| Field | Type | Required | Description | |------------|----------|----------|----------------------------| | host | string | Yes | Database host. | | port | number | Yes | Database port (e.g. 3306). | | user | string | Yes | Database username. | | password | string | Yes | Database password. | | database | string | Yes | Database name. |

PostgreSQL Configuration

| Field | Type | Required | Description | |-------------------------------|-----------|----------|--------------------------------------------------------| | host | string | Yes | Database host. | | port | number | Yes | Database port (e.g. 5432). | | user | string | Yes | Database username. | | password | string | Yes | Database password. | | database | string | Yes | Database name. | | schema | string | No | Introspected schema (defaults to 'public'). | | includeForeignKeysAsIndexes | boolean | No | Treat FKs as indexes (defaults to false). |

Standardized Format (Item)

Each item represent a table in your database.

| Property | Type | Required | Description | |--------------|-----------------------|----------|-------------------------------------| | table | string | Yes | Table name. | | schema | string | Yes | Schema or database name. | | columns | Column[] | Yes | Array of column definitions. | | indexes | Index[] | Yes | Array of index definitions. | | relations | Relation[] | Yes | Foreign key relationships. | | primaryKey | { columns: string[] } | Yes | List of primary key columns. |

Column Detail

| Property | Type | Required | Description | |-----------------|------------|----------|----------------------------------------------| | name | string | Yes | Column name. | | type | string | Yes | Canonical type (string, int, date, boolean, float). | | subType | string | No | More specific type (e.g. datetime, json). | | nullable | boolean | Yes | Whether it accepts NULL. | | default | any | Yes | Default value. | | comment | string | Yes | Database comment/description. | | unsigned | boolean | No | Whether it's numeric unsigned. | | autoincrement | boolean | No | Whether it's an identity/auto-increment. | | size | number | No | Max length or precision. | | scale | number | No | Decimal scale. | | enum | string[] | No | Allowed values for enum types. |

Index Detail

| Property | Type | Required | Description | |-----------|---------------------|----------|------------------------------------| | type | 'unique' | 'index' | Yes | Type of index (unique or regular). | | columns | string[] | Yes | Columns involved in the index. | | index | string | Yes | Name of the index. |

Relation Detail

| Property | Type | Required | Description | |---------------|----------------------------|----------|----------------------------------------------| | type | 'belongs-to' | 'has-many' | Yes | Type of relationship between tables. | | columns | string[] | Yes | Columns involved in the relationship. | | references | string[] | Yes | Columns referenced in the related table. | | on | object | Yes | Details of the related table. | | on.database | string | Yes | Schema/Database of the related table. | | on.table | string | Yes | Name of the related table. |