@pgtyped/cli
This package provides the pgtyped
command.
pgtyped
supports two modes: normal and watch mode.
In normal mode, pgtyped
operates as follows:
- Scans your
srcDir
for query files. Query file name format is specified using the queryFileName
config option.
- Extracts all queries defined in query files using the
sql
tagged template.
- Connects to your database and fetches the input and output types for all the queries found in step 3.
- For each query file, saves its queries type declaration in a query type declaration file (defined by the
emitFileName
option of the config.
- Exit
Watch mode operation is the same, except that pgtyped
doesn't exit after processing all files, but continues running in the background, watching srcDir
for changes and regenerating query types files on file change or creation.
Config file:
Config file format (config.json
):
{
"emit": {
"mode": "query-file",
"queryFileName": "queries.ts",
"emitFileName": "queries.types.ts"
},
"srcDir": "./src/",
"db": {
"dbName": "testdb",
"user": "user",
"password": "password",
"host": "127.0.0.1"
}
}
This package is part of the pgtyped project.
Refer to root README for details.