Description
Generate typescript interfaces from a postgresql schema.
Config
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"
}
}
}
Options
--config <config>
, -c <config>
Set a relative path to the config to use.
--config-root <path.to.properties>
, -r <path.to.properties>
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 <filename>
, -o <filename>
Output filename.
Examples
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
,