mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(Postgres Node): Remove reusable connections (no-changelog) (#6259)
This commit is contained in:
@@ -11,7 +11,7 @@ import pgPromise from 'pg-promise';
|
||||
import { rm, writeFile } from 'fs/promises';
|
||||
import { file } from 'tmp-promise';
|
||||
|
||||
import type { PgpClient, PgpDatabase } from '../helpers/interfaces';
|
||||
import type { PgpDatabase } from '../helpers/interfaces';
|
||||
|
||||
async function createSshConnectConfig(credentials: IDataObject) {
|
||||
if (credentials.sshAuthenticateWith === 'password') {
|
||||
@@ -40,12 +40,16 @@ async function createSshConnectConfig(credentials: IDataObject) {
|
||||
}
|
||||
}
|
||||
|
||||
async function configurePostgres(
|
||||
export async function configurePostgres(
|
||||
credentials: IDataObject,
|
||||
options: IDataObject = {},
|
||||
createdSshClient?: Client,
|
||||
) {
|
||||
const pgp = pgPromise();
|
||||
const pgp = pgPromise({
|
||||
// prevent spam in console "WARNING: Creating a duplicate database object for the same connection."
|
||||
// duplicate connections created when auto loading parameters, they are closed imidiatly after, but several could be open at the same time
|
||||
noWarnings: true,
|
||||
});
|
||||
|
||||
if (typeof options.nodeVersion == 'number' && options.nodeVersion >= 2.1) {
|
||||
// Always return dates as ISO strings
|
||||
@@ -183,36 +187,3 @@ async function configurePostgres(
|
||||
return { db, pgp, sshClient };
|
||||
}
|
||||
}
|
||||
|
||||
export const Connections = (function () {
|
||||
let instance: { db: PgpDatabase; pgp: PgpClient; sshClient?: Client } | null = null;
|
||||
|
||||
return {
|
||||
async getInstance(
|
||||
credentials: IDataObject = {},
|
||||
options: IDataObject = {},
|
||||
reload = false,
|
||||
createdSshClient?: Client,
|
||||
nulify = false,
|
||||
) {
|
||||
if (nulify) {
|
||||
instance = null;
|
||||
return instance;
|
||||
}
|
||||
|
||||
if (instance !== null && reload) {
|
||||
if (instance.sshClient) {
|
||||
instance.sshClient.end();
|
||||
}
|
||||
instance.pgp.end();
|
||||
|
||||
instance = null;
|
||||
}
|
||||
|
||||
if (instance === null && Object.keys(credentials).length) {
|
||||
instance = await configurePostgres(credentials, options, createdSshClient);
|
||||
}
|
||||
return instance;
|
||||
},
|
||||
};
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user