mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(MySQL Node): Overhaul
This commit is contained in:
44
packages/nodes-base/nodes/MySql/v2/methods/credentialTest.ts
Normal file
44
packages/nodes-base/nodes/MySql/v2/methods/credentialTest.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import type {
|
||||
ICredentialDataDecryptedObject,
|
||||
ICredentialsDecrypted,
|
||||
ICredentialTestFunctions,
|
||||
INodeCredentialTestResult,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { createPool } from '../transport';
|
||||
|
||||
import { Client } from 'ssh2';
|
||||
|
||||
export async function mysqlConnectionTest(
|
||||
this: ICredentialTestFunctions,
|
||||
credential: ICredentialsDecrypted,
|
||||
): Promise<INodeCredentialTestResult> {
|
||||
const credentials = credential.data as ICredentialDataDecryptedObject;
|
||||
|
||||
let sshClient: Client | undefined = undefined;
|
||||
|
||||
if (credentials.sshTunnel) {
|
||||
sshClient = new Client();
|
||||
}
|
||||
const pool = await createPool(credentials, {}, sshClient);
|
||||
|
||||
try {
|
||||
const connection = await pool.getConnection();
|
||||
connection.release();
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 'Error',
|
||||
message: error.message,
|
||||
};
|
||||
} finally {
|
||||
if (sshClient) {
|
||||
sshClient.end();
|
||||
}
|
||||
await pool.end();
|
||||
}
|
||||
|
||||
return {
|
||||
status: 'OK',
|
||||
message: 'Connection successful!',
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user