brf/server/lib/knex.ts
2025-12-13 21:12:08 +01:00

34 lines
763 B
TypeScript

import _ from 'lodash'
import knex from 'knex'
// @ts-ignore
import pg from 'pg'
import env from '../env.ts'
const queryProto = pg.Query.prototype
const handleRowDescription = queryProto.handleRowDescription
queryProto.handleRowDescription = function (msg: { fields: { name: string }[] }) {
msg.fields.forEach((field: { name: string }) => {
field.name = _.camelCase(field.name)
})
return handleRowDescription.call(this, msg)
}
export default knex({
client: 'pg',
wrapIdentifier: (value, origImpl) => (value === '*' ? value : origImpl(_.snakeCase(value))),
connection: {
database: env.PGDATABASE,
host: env.PGHOST,
password: env.PGPASSWORD,
port: env.PGPORT,
user: env.PGUSER,
},
acquireConnectionTimeout: 30000,
})