import Knex from 'knex' ; import path from 'path' ; import environment from '../../environment' ; import { snakeCase , camelCase } from 'change-case' ; function convertRow2CamelCase ( row ) { if ( ! row ) return row ; return Object . entries ( row ) . reduce ( ( acc , cur ) => { acc [ camelCase ( cur [ 0 ] ) ] = cur [ 1 ] ; return acc ; } , { } ) ; } const knexConfig = { client : environment . database . client , connection : { host : environment . database . host , port : environment . database . port , user : environment . database . user , password : environment . database . password , database : environment . database . database , ssl : environment . database . ssl , } , migrations : { directory : path . resolve ( __dirname , '../../migrations' ) , } , pool : { min : 0 , } , debug : ! ! process . env . KNEX_DEBUG , wrapIdentifier : ( value , origImpl ) => origImpl ( snakeCase ( value ) ) , postProcessResponse : result => { if ( Array . isArray ( result ) ) { return result . map ( row => convertRow2CamelCase ( row ) ) ; } else { return convertRow2CamelCase ( result ) ; } } , } ; export = knexConfig ;