Codegen configuration
Install @sqlbraid/cli, @sqlbraid/codegen, the selected dialect and the driver in your tooling project. Create an executable Node config (.mjs, .js or .cjs):
import { defineConfig } from "@sqlbraid/cli/config";import { typePolicyForProfile } from "@sqlbraid/postgres";
const typePolicy = typePolicyForProfile({ json: "text", temporal: "text" });
export default defineConfig({ codegen: { targets: [ { name: "main", metadata: "./db/main.metadata.json", outFile: "./src/generated/database.ts", typePolicy, filters: { includeNamespaces: ["public"] }, }, ], },});Run this command from the project that contains the config:
pnpm exec sqlbraid codegenpnpm exec sqlbraid codegen --config ./sqlbraid.config.mjspnpm exec sqlbraid codegen --target main --checkpnpm exec sqlbraid codegen --jsonThe metadata and output paths are relative to the config file.
- Repeat
--targetto select many targets. - Validation completes for each selected target before any output is written.
- Generated files that do not change keep their mtime.
- The JSON result reports
writtenonly after the I/O is successful.
The config is trusted Node code that the CLI executes. It is not a sandbox. If the project needs schema changes that people can review, keep the metadata and the generated output under version control.
TypePolicy defines how database column types map to TypeScript types. Pass the same PostgreSQL, mysql2, or MariaDB profile descriptor in your codegen config that you pass to the database factory at runtime. Native JSON columns stay unknown unless a type override narrows them. Type overrides change only the emitted TypeScript declarations. They do not change runtime decoding.