File tree Expand file tree Collapse file tree 6 files changed +777
-0
lines changed Expand file tree Collapse file tree 6 files changed +777
-0
lines changed Original file line number Diff line number Diff line change 2525 "gen:types:typescript" : " PG_META_GENERATE_TYPES=typescript node --loader ts-node/esm src/server/server.ts" ,
2626 "gen:types:go" : " PG_META_GENERATE_TYPES=go node --loader ts-node/esm src/server/server.ts" ,
2727 "gen:types:swift" : " PG_META_GENERATE_TYPES=swift node --loader ts-node/esm src/server/server.ts" ,
28+ "gen:types:python" : " PG_META_GENERATE_TYPES=python node --loader ts-node/esm src/server/server.ts" ,
2829 "start" : " node dist/server/server.js" ,
2930 "dev" : " trap 'npm run db:clean' INT && run-s db:clean db:run && run-s dev:code" ,
3031 "dev:code" : " nodemon --exec node --loader ts-node/esm src/server/server.ts | pino-pretty --colorize" ,
Original file line number Diff line number Diff line change 1+ import type { FastifyInstance } from 'fastify'
2+ import { PostgresMeta } from '../../../lib/index.js'
3+ import { createConnectionConfig , extractRequestForLogging } from '../../utils.js'
4+ import { apply as applyPyTemplate } from '../../templates/python.js'
5+ import { getGeneratorMetadata } from '../../../lib/generators.js'
6+
7+ export default async ( fastify : FastifyInstance ) => {
8+ fastify . get < {
9+ Headers : { pg : string ; 'x-pg-application-name' ?: string }
10+ Querystring : {
11+ excluded_schemas ?: string
12+ included_schemas ?: string
13+ }
14+ } > ( '/' , async ( request , reply ) => {
15+ const config = createConnectionConfig ( request )
16+ const excludedSchemas =
17+ request . query . excluded_schemas ?. split ( ',' ) . map ( ( schema ) => schema . trim ( ) ) ?? [ ]
18+ const includedSchemas =
19+ request . query . included_schemas ?. split ( ',' ) . map ( ( schema ) => schema . trim ( ) ) ?? [ ]
20+ const pgMeta : PostgresMeta = new PostgresMeta ( config )
21+ const { data : generatorMeta , error : generatorMetaError } = await getGeneratorMetadata ( pgMeta , {
22+ includedSchemas,
23+ excludedSchemas,
24+ } )
25+ if ( generatorMetaError ) {
26+ request . log . error ( { error : generatorMetaError , request : extractRequestForLogging ( request ) } )
27+ reply . code ( 500 )
28+ return { error : generatorMetaError . message }
29+ }
30+
31+ return applyPyTemplate ( generatorMeta )
32+ } )
33+ }
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import ViewsRoute from './views.js'
2121import TypeScriptTypeGenRoute from './generators/typescript.js'
2222import GoTypeGenRoute from './generators/go.js'
2323import SwiftTypeGenRoute from './generators/swift.js'
24+ import PythonTypeGenRoute from './generators/python.js'
2425import { PG_CONNECTION , CRYPTO_KEY } from '../constants.js'
2526
2627export default async ( fastify : FastifyInstance ) => {
@@ -82,4 +83,5 @@ export default async (fastify: FastifyInstance) => {
8283 fastify . register ( TypeScriptTypeGenRoute , { prefix : '/generators/typescript' } )
8384 fastify . register ( GoTypeGenRoute , { prefix : '/generators/go' } )
8485 fastify . register ( SwiftTypeGenRoute , { prefix : '/generators/swift' } )
86+ fastify . register ( PythonTypeGenRoute , { prefix : '/generators/python' } )
8587}
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import {
1818import { apply as applyTypescriptTemplate } from './templates/typescript.js'
1919import { apply as applyGoTemplate } from './templates/go.js'
2020import { apply as applySwiftTemplate } from './templates/swift.js'
21+ import { apply as applyPythonTemplate } from './templates/python.js'
2122
2223const logger = pino ( {
2324 formatters : {
@@ -143,6 +144,8 @@ async function getTypeOutput(): Promise<string | null> {
143144 } )
144145 case 'go' :
145146 return applyGoTemplate ( config )
147+ case 'python' :
148+ return applyPythonTemplate ( config )
146149 default :
147150 throw new Error ( `Unsupported language for GENERATE_TYPES: ${ GENERATE_TYPES } ` )
148151 }
You can’t perform that action at this time.
0 commit comments