Options
All
  • Public
  • Public/Protected
  • All
Menu

ElbowGrease

ElbowGrease

npm Build Status

When you need TypeScript classes corresponding to your database tables - you need some ElbowGrease.

MySQL and PostgreSQL supported.

Super lightweight: not a single dependency

Example

customer
idint not null
emailtext not null
passwordtext
created_attimestamp not null

With config:

{
    "extends": "AutoBase",
    "attribute": "@serializable"
}

Will result in

export class customer extends AutoBase
{
    @serializable
    id: number

    @serializable
    email: string

    @serializable
    password: string | null

    @serializable
    created_at: Date
}

Installing ElbowGrease

npm install -g elbowgrease

And depending on the database you're going to connect to:

npm install -g pg    # for postgres
npm install -g mysql # for mysql

Generating the code

elbowgrease postgres://user:password@host/database output.ts
elbowgrease mysql://user:password@host/database output.ts

Using elbowgrease.json config file

Just run your generation with

elbowgrease

with elbowgrease.json in curren directory

{
    "connectionData": "postgres://user:password@host/database",
    "output": "ts/types.ts"
}
{
    "connectionData": {
        "host": "hostname",
        "user": "username"
    },
    "output": "ts/types.ts"
}

Options

{
    "excludeTables": [],
    "schema": "public",
    "extends": "",
    "dialect": "postgres",
    "exportKeyword": "class",
    "attribute": "",
    "indent": "    ",
    "memberCase": "none",
    "typeCase": "none",
    "prepend": "",
    "append": "",
    "lineFeed": "\n",
    "header": true,
    "additional_info": {}
}