콘텐츠로 이동

Codegen 설정

도구 프로젝트에 @sqlbraid/cli, @sqlbraid/codegen, 선택한 dialect, 드라이버를 설치하세요. 실행 가능한 Node 설정(.mjs, .js, .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"] },
}],
},
});

설정이 있는 프로젝트에서 실행하세요.

터미널 창
sqlbraid codegen
sqlbraid codegen --config ./sqlbraid.config.mjs
sqlbraid codegen --target main --check
sqlbraid codegen --json

메타데이터와 출력 경로는 설정 파일을 기준으로 합니다. 반복된 --target은 여러 대상을 선택합니다. 출력물을 쓰기 전에 선택한 모든 대상의 검증이 완료되며, 변경되지 않은 생성 파일은 mtime을 유지합니다. JSON 결과는 I/O가 성공한 뒤에만 written을 보고합니다.

설정은 신뢰된 실행 가능한 Node 코드이며 sandbox가 아닙니다. 프로젝트에서 검토 가능한 스키마 변경이 필요하다면 메타데이터와 생성 출력을 버전 관리에 포함하세요.

선택한 TypePolicy는 꾸밈용 codegen option이 아니라 representation profile입니다. 같은 PostgreSQL/mysql2/MariaDB profile descriptor를 runtime과 이 설정에서 재사용하세요. Native JSON root는 driver 계약이 좁히지 않는 한 의도적으로 unknown이며, 수동 output override는 TypeScript 출력만 바꾸고 runtime decode를 바꾸지 않습니다.