pool.afterCreate no longer supported?
See original GitHub issueEnvironment
Knex version: 0.19.0 Database + version: PostgreSQL 10.5 OS: macOS Mojave 10.14.15
It appears the afterCreate
hook inside of the pool
configuration is no longer available, yet the documentation still lists it as a viable option: http://knexjs.org/#Installation-pooling-afterCreate
Based on reading the changelog and upgrade guide, I can see that there is some callout to using tarn.js
to manage these types of hooks ourselves, but I’m not seeing any actionable information on how to actually do this.
-
It would be nice for the documentation to be updated when a breaking change like this is introduced.
-
I’m looking for guidance on the “tarn.js way” of doing the following (this is effectively the same example provided in the knex documentation) - see code below.
The issue I’m facing is that I can’t seem to figure out how to override the pool configuration with my own tarn.js pool, since instantiating a tarn.js pool requires passing in the DB client somehow. (see here: https://github.com/vincit/tarn.js#usage)
const dbClient = Knex({
client: 'pg',
useNullAsDefault: true,
connection: {
host: config.get('dbHost'),
user: config.get('dbUser'),
password: config.get('dbPassword'),
database: config.get('dbName'),
timezone: 'UTC',
},
searchPath: ['public'],
pool: {
min: 2,
afterCreate: (connection, callback) => {
connection.query(`SET timezone to 'UTC'`, err =>
callback(err, connection),
);
}
},
});
Any help would be greatly appreciated, and as always, thank you for the stellar work on knex.
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (4 by maintainers)
In my case, on PG 12.11 and knex 2.1 the afterCreate didn’t work, thankfully the other option worked just fine
My example in case another googler ends up here
Anyways test case for afterCreate should be added. That is why I have left this open.