When you need TypeScript classes corresponding to your database tables - you need some ElbowGrease.
MySQL and PostgreSQL supported.
Super lightweight: not a single dependency
customer | |
---|---|
id | int not null |
text not null | |
password | text |
created_at | timestamp 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
}
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
elbowgrease postgres://user:password@host/database output.ts
elbowgrease mysql://user:password@host/database output.ts
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"
}
{
"excludeTables": [],
"schema": "public",
"extends": "",
"dialect": "postgres",
"exportKeyword": "class",
"attribute": "",
"indent": " ",
"memberCase": "none",
"typeCase": "none",
"prepend": "",
"append": "",
"lineFeed": "\n",
"header": true,
"additional_info": {}
}