I would like to use knex as a query builder, but my project already handles its own connection pool.
I wish I could to do something like:
const { Client } = require('pg')
const client = new Client()
await client.connect()
const knex = require('knex')({
client: 'pg',
connection: client,
})
Is there any way to provide knex with the pg client object, instead of letting it to manage its own connection pool?
No. Unless you write your own custom dialect and override connection fetching functionality. Writing custom dialect is described here https://github.com/tgriesser/knex/blob/master/CONTRIBUTING.md#i-would-like-to-add-support-for-new-dialect-to-knex-is-it-possible