Generate TypeScript types to be used with the PostgreSQL-Typed ecosystem from your PostgreSQL database.
Install @postgresql-typed/cli as a development dependency.
npm install --save-dev @postgresql-typed/cli
To initialize a new configuration file for PostgreSQL-Typed in your current working directory, run pgt init
.
npx pgt init
By default, this will create a pgt.config.ts
file in your current working directory with the following contents:
import { defineConfig } from "@postgresql-typed/cli/config";
export default defineConfig({
cli: {
connections: [
process.env.DATABASE_URI
],
},
});
You can then run pgt gen
to generate TypeScript types for your database.
Make sure to set the DATABASE_URI
environment variable to your database connection string before running this command.
You can use a .env
file to set environment variables. This file will be automatically loaded by pgt
.
NOTE: If your project uses ESM modules, you will need to set the cli.type
option to "esm"
in your pgt.config.ts
file.
npx pgt gen
By default, this will create a __generated__
directory in your current working directory with the generated TypeScript types.
You can customize the output directory and many other options by editing the pgt.config.ts
file. See the JSDoc comments when hovering for more information.
You can also run pgt --help
to see a list of available commands.
This package is part of the PostgreSQL-Typed ecosystem.