first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import type {
|
||||
ICredentialsDecrypted,
|
||||
ICredentialTestFunctions,
|
||||
INodeCredentialTestResult,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import type { MysqlNodeCredentials } from '../helpers/interfaces';
|
||||
import { createPool } from '../transport';
|
||||
|
||||
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!',
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export * as credentialTest from './credentialTest';
|
||||
export * as listSearch from './listSearch';
|
||||
export * as loadOptions from './loadOptions';
|
||||
@@ -0,0 +1,34 @@
|
||||
import type { IDataObject, ILoadOptionsFunctions, INodeListSearchResult } from 'n8n-workflow';
|
||||
|
||||
import type { MysqlNodeCredentials } from '../helpers/interfaces';
|
||||
import { createPool } from '../transport';
|
||||
|
||||
export async function searchTables(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
|
||||
const credentials = await this.getCredentials<MysqlNodeCredentials>('mySql');
|
||||
|
||||
const nodeOptions = this.getNodeParameter('options', 0) as IDataObject;
|
||||
|
||||
const pool = await createPool.call(this, credentials, nodeOptions);
|
||||
|
||||
try {
|
||||
const connection = await pool.getConnection();
|
||||
|
||||
const query = 'SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = ?';
|
||||
const values = [credentials.database];
|
||||
|
||||
const formatedQuery = connection.format(query, values);
|
||||
|
||||
const response = (await connection.query(formatedQuery))[0];
|
||||
|
||||
connection.release();
|
||||
|
||||
const results = (response as IDataObject[]).map((table) => ({
|
||||
name: (table.table_name as string) || (table.TABLE_NAME as string),
|
||||
value: (table.table_name as string) || (table.TABLE_NAME as string),
|
||||
}));
|
||||
|
||||
return { results };
|
||||
} finally {
|
||||
await pool.end();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import type { IDataObject, ILoadOptionsFunctions, INodePropertyOptions } from 'n8n-workflow';
|
||||
|
||||
import type { MysqlNodeCredentials } from '../helpers/interfaces';
|
||||
import { escapeSqlIdentifier } from '../helpers/utils';
|
||||
import { createPool } from '../transport';
|
||||
|
||||
export async function getColumns(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const credentials = await this.getCredentials<MysqlNodeCredentials>('mySql');
|
||||
const nodeOptions = this.getNodeParameter('options', 0) as IDataObject;
|
||||
|
||||
const pool = await createPool.call(this, credentials, nodeOptions);
|
||||
|
||||
try {
|
||||
const connection = await pool.getConnection();
|
||||
|
||||
const table = this.getNodeParameter('table', 0, {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
const columns = (
|
||||
await connection.query(
|
||||
`SHOW COLUMNS FROM ${escapeSqlIdentifier(table)} FROM ${escapeSqlIdentifier(
|
||||
credentials.database,
|
||||
)}`,
|
||||
)
|
||||
)[0] as IDataObject[];
|
||||
|
||||
connection.release();
|
||||
|
||||
return (columns || []).map((column: IDataObject) => ({
|
||||
name: column.Field as string,
|
||||
value: column.Field as string,
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-description-lowercase-first-char
|
||||
description: `type: ${(column.Type as string).toUpperCase()}, nullable: ${
|
||||
column.Null as string
|
||||
}`,
|
||||
}));
|
||||
} finally {
|
||||
await pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
export async function getColumnsMultiOptions(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
const returnData = await getColumns.call(this);
|
||||
const returnAll = { name: '*', value: '*', description: 'All columns' };
|
||||
return [returnAll, ...returnData];
|
||||
}
|
||||
|
||||
export async function getColumnsWithoutColumnToMatchOn(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
const columnToMatchOn = this.getNodeParameter('columnToMatchOn') as string;
|
||||
const returnData = await getColumns.call(this);
|
||||
return returnData.filter((column) => column.value !== columnToMatchOn);
|
||||
}
|
||||
Reference in New Issue
Block a user