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

generathor-db

v1.0.2

Published

Use this to get database info

Downloads

237

Readme

Generathor-DB

Generathor-DB retrieves the structure of a database, including tables, columns, indexes, relations, and primary keys in a standardized format. This allows for the automation of code generation, such as models, controllers, migrations, and more, based on the database schema.

How does it work?

Generathor-DB requires a configuration object to connect to the database. Optionally, you can pass an array of transformers to modify the data before it is used to generate files.

import { Source } from 'generathor-db';

const source = new Source({
  type: 'mysql',
  configuration: {
    host: 'localhost',
    port: '3306',
    user: 'root',
    password: 'password',
    database: 'generathor'
  }
}, [
    (item) => {
      item.columns.forEach(column => {
        column.calculated = column.name.toUpperCase(); // Example transformation
      });
    }
]);

Parameters

| Variable | Required | Type | Description | |-----------------------|----------|---------------------------------------------|--------------------------------------------------| | sourceConfiguration | Yes | SourceConfiguration | Configuration to connect to the database. | | transformer | No | Transformer[] | Array of functions to modify items before usage. |

SourceConfiguration

| Variable | Required | Type | Description | |-----------------|----------|-------------------------------------------|--------------------------------------| | type | Yes | 'mysql' | At the moment we only support mysql. | | configuration | Yes | MySQLConfiguration | Configuration for the database. |

MySQLConfiguration

See mysql2 for more information.

Transformer

Callback that receives the items and allows you to modify or add information for file generation.

Item format

This source retrieves an array of items, and each item has information about one table of the database.

| Variable | Required | Type | Description | |----------------------|----------|---------------------------|-------------------------------------| | table | Yes | string | Name of the table. | | schema | Yes | string | Name of the schema. | | columns | Yes | Column[] | List of columns in the table. | | indexes | Yes | Index[] | List of indexes in the table. | | relations | Yes | Relation[] | List of table relations. | | primaryKey | Yes | object | Primary key of the table. | | primaryKey.columns | Yes | string[] | List of columns in the primary key. |

Column

| Variable | Required | Type | Description | |----------------|----------|---------------------------|-----------------------------------------------| | name | Yes | string | Name of the column. | | nullable | Yes | boolean | Indicates if column allows null values. | | default | Yes | string | Default value of the column. | | comment | Yes | string | Comment or description of the column. | | type | Yes | string | Type of column (e.g., int, varchar). | | subType | No | string | Subtype of the column, if applicable. | | unsigned | No | boolean | Indicates if the column is unsigned. | | enum | No | string[] | List of valid values for enum types. | | size | No | number | Size of the column (if applicable). | | autoincrement| No | boolean | Indicates if the column auto-increments. | | scale | No | number | Decimal scale for numeric columns. |

Index

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

Relation

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

TODO

  • [ ] Add support for additional database engines (PostgreSQL, SQLite, etc.).