2023-04-12 07:24:17 -07:00
|
|
|
import type {
|
|
|
|
ICredentialsDecrypted,
|
|
|
|
ICredentialTestFunctions,
|
|
|
|
INodeCredentialTestResult,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
import { createPool } from '../transport';
|
2024-07-04 03:29:44 -07:00
|
|
|
import type { MysqlNodeCredentials } from '../helpers/interfaces';
|
2023-04-12 07:24:17 -07:00
|
|
|
|
|
|
|
export async function mysqlConnectionTest(
|
|
|
|
this: ICredentialTestFunctions,
|
|
|
|
credential: ICredentialsDecrypted,
|
|
|
|
): Promise<INodeCredentialTestResult> {
|
2024-07-04 03:29:44 -07:00
|
|
|
const credentials = credential.data as MysqlNodeCredentials;
|
2023-04-12 07:24:17 -07:00
|
|
|
|
2024-07-04 03:29:44 -07:00
|
|
|
const pool = await createPool.call(this, credentials);
|
2023-04-12 07:24:17 -07:00
|
|
|
|
|
|
|
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!',
|
|
|
|
};
|
|
|
|
}
|