UNPKG

knex-dynamic-connection

Version:

Adds support for dynamically returning connection config for knex queries

33 lines (32 loc) 1.11 kB
"use strict"; /* * knex-dynamic-connection * * (c) Harminder Virk <virk@adonisjs.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.acquireRawConnection = void 0; /** * Copy of `acquireRawConnection` from knex codebase, but instead relies * on `getRuntimeConnectionSettings` vs `connectionSettings` */ function acquireRawConnection() { return new Promise((resolver, rejecter) => { const connection = this.driver.createConnection(this.getRuntimeConnectionSettings()); connection.on('error', (err) => { connection.__knex__disposed = err; }); connection.connect((err) => { if (err) { // if connection is rejected, remove listener that was registered above... connection.removeAllListeners(); return rejecter(err); } resolver(connection); }); }); } exports.acquireRawConnection = acquireRawConnection;