n8n/packages/nodes-base/nodes/MySql/v2/methods/credentialTest.ts
कारतोफ्फेलस्क्रिप्ट™ 85aa560a5d
refactor(core): Centralize SSH Tunnel management (#9906)
Co-authored-by: Michael Kret <michael.k@radency.com>
2024-07-04 12:29:44 +02:00

35 lines
768 B
TypeScript

import type {
ICredentialsDecrypted,
ICredentialTestFunctions,
INodeCredentialTestResult,
} from 'n8n-workflow';
import { createPool } from '../transport';
import type { MysqlNodeCredentials } from '../helpers/interfaces';
export async function mysqlConnectionTest(
this: ICredentialTestFunctions,
credential: ICredentialsDecrypted,
): Promise<INodeCredentialTestResult> {
const credentials = credential.data as MysqlNodeCredentials;
const pool = await createPool.call(this, credentials);
try {
const connection = await pool.getConnection();
connection.release();
} catch (error) {
return {
status: 'Error',
message: error.message,
};
} finally {
await pool.end();
}
return {
status: 'OK',
message: 'Connection successful!',
};
}