fastify-knexjs
fastify-knexjs copied to clipboard
Multiple Knex configuration
Hi everyone, I'm Davide! I have multiple database connection and I can't register the plugin for all these connection. I receive the message
FastifyError [FST_ERR_DEC_ALREADY_PRESENT]: The decorator 'knex' has already been added!
Is there any reason why this cannot be done? I think that with a simple update it's possible to manage multiple knex instance. For example:
...
const name = opts.name || 'knex'
if (opts.name) {
delete opts.name
}
const handler = knex(opts);
fastify
.decorate(name, handler)
.addHook('onClose', (instance, done) => {
/* istanbul ignore else */
if (instance.name === handler) {
instance.name.destroy();
delete instance.name;
}
done();
});
...
Can I send a pull request with these updates? It would be great for me to help develop the plugin! Thanks