mirror of
https://github.com/arthur-pbty/portfolio2023.git
synced 2026-06-07 23:04:51 +02:00
44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
"use strict";
|
|
/* eslint-disable @typescript-eslint/no-shadow */
|
|
/*
|
|
* 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`
|
|
*/
|
|
/* eslint no-shadow: "off" */
|
|
function acquireRawConnection() {
|
|
const client = this;
|
|
const connection = new client.driver.Client(client.getRuntimeConnectionSettings());
|
|
connection.on('error', (err) => {
|
|
connection.__knex__disposed = err;
|
|
});
|
|
connection.on('end', (err) => {
|
|
connection.__knex__disposed = err || 'Connection ended unexpectedly';
|
|
});
|
|
return connection
|
|
.connect()
|
|
.then(() => {
|
|
if (!client.version) {
|
|
return client.checkVersion(connection).then(function (version) {
|
|
client.version = version;
|
|
return connection;
|
|
});
|
|
}
|
|
return connection;
|
|
})
|
|
.then(function setSearchPath(connection) {
|
|
client.setSchemaSearchPath(connection);
|
|
return connection;
|
|
});
|
|
}
|
|
exports.acquireRawConnection = acquireRawConnection;
|