Generate typescript interfaces from a postgresql schema.
npm install @ist-group/pg-typegenGenerate typescript interfaces from a postgresql schema.
The type-gen will look for database connection information in the config. The connection information is directly put into pg-promise. See pg-promise connection syntax for more information if needed.
Expected propertes:
```
host: string
port: number
database: string
user: string
password: string
Example:
``
{
"host": "localhost",
"port": 5432,
"database": "local-database",
"user": "root",
"password": "root"
}
There is a possibility to set a root of the properties inside the json file with --config-root. This is useful if the database information is not at root level.
Example:
`
pg-types --config ./config.json --config-root db.config --output ./output.ts
./config.json
{
"db": {
"config": {
"host": "localhost",
"port": 5432,
"database": "local-database",
"user": "root",
"password": "root"
}
}
}
`
--config , -c Set a relative path to the config to use.
--config-root , -r Set a root of the expected properties in the given config file.
--desnake, -d Replace snake_casing with CamelCasing in the generated output.
``
interface table_name {
column_name: number;
}
will become
``
interface TableName {
columnName: number;
}
--output , -o Output filename.
pg-types --config ./config.json ./output.ts,pg-types --config ./config.json --config-root db.config --output ./output.ts,pg-types --config ./config.json -d ./output.ts`,