34 lines
763 B
TypeScript
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,
|
|
})
|