brf/server/lib/knex.ts
2025-11-23 21:44:01 +01:00

34 lines
754 B
TypeScript

import _ from 'lodash'
// eslint-disable-next-line import/no-named-as-default
import knex from 'knex'
import pg from 'pg'
import env from '../env.ts'
const queryProto = pg.Query.prototype
const handleRowDescription = queryProto.handleRowDescription
queryProto.handleRowDescription = function (msg) {
msg.fields.forEach((field) => {
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,
})