Skip to content

Commit 5559285

Browse files
committed
fix: add x-application-name header, add python to server.ts
1 parent 859a5d6 commit 5559285

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/server/routes/generators/python.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
import type { FastifyInstance } from 'fastify'
22
import { PostgresMeta } from '../../../lib/index.js'
3-
import { DEFAULT_POOL_CONFIG } from '../../constants.js'
4-
import { extractRequestForLogging } from '../../utils.js'
3+
import { createConnectionConfig, extractRequestForLogging } from '../../utils.js'
54
import { apply as applyPyTemplate } from '../../templates/python.js'
65
import { getGeneratorMetadata } from '../../../lib/generators.js'
76

87
export default async (fastify: FastifyInstance) => {
98
fastify.get<{
10-
Headers: { pg: string }
9+
Headers: { pg: string; 'x-pg-application-name'?: string }
1110
Querystring: {
1211
excluded_schemas?: string
1312
included_schemas?: string
1413
}
1514
}>('/', async (request, reply) => {
16-
const connectionString = request.headers.pg
15+
const config = createConnectionConfig(request)
1716
const excludedSchemas =
1817
request.query.excluded_schemas?.split(',').map((schema) => schema.trim()) ?? []
1918
const includedSchemas =
2019
request.query.included_schemas?.split(',').map((schema) => schema.trim()) ?? []
21-
22-
const pgMeta: PostgresMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
20+
const pgMeta: PostgresMeta = new PostgresMeta(config)
2321
const { data: generatorMeta, error: generatorMetaError } = await getGeneratorMetadata(pgMeta, {
2422
includedSchemas,
2523
excludedSchemas,

src/server/server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { apply as applyTypescriptTemplate } from './templates/typescript.js'
1919
import { apply as applyGoTemplate } from './templates/go.js'
2020
import { apply as applySwiftTemplate } from './templates/swift.js'
21+
import { apply as applyPythonTemplate } from './templates/python.js'
2122

2223
const 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
}

0 commit comments

Comments
 (0)