mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(MySql Node): use resource locator component for table parameter (#4313)
insert/update operation table parameter as resource locator
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { IDataObject, INodeExecutionData } from 'n8n-workflow';
|
||||
import { ICredentialDataDecryptedObject, IDataObject, ILoadOptionsFunctions, INodeExecutionData, INodeListSearchResult } from 'n8n-workflow';
|
||||
import mysql2 from 'mysql2/promise';
|
||||
|
||||
/**
|
||||
* Returns of copy of the items which only contains the json data and
|
||||
@@ -22,3 +23,44 @@ export function copyInputItems(items: INodeExecutionData[], properties: string[]
|
||||
return newItem;
|
||||
});
|
||||
}
|
||||
|
||||
export function createConnection(credentials: ICredentialDataDecryptedObject): Promise<mysql2.Connection> {
|
||||
const { ssl, caCertificate, clientCertificate, clientPrivateKey, ...baseCredentials } =
|
||||
credentials;
|
||||
|
||||
if (ssl) {
|
||||
baseCredentials.ssl = {};
|
||||
|
||||
if (caCertificate) {
|
||||
baseCredentials.ssl.ca = caCertificate;
|
||||
}
|
||||
|
||||
if (clientCertificate || clientPrivateKey) {
|
||||
baseCredentials.ssl.cert = clientCertificate;
|
||||
baseCredentials.ssl.key = clientPrivateKey;
|
||||
}
|
||||
}
|
||||
|
||||
return mysql2.createConnection(baseCredentials);
|
||||
}
|
||||
|
||||
export async function searchTables(
|
||||
this: ILoadOptionsFunctions,
|
||||
query?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const credentials = await this.getCredentials('mySql');
|
||||
const connection = await createConnection(credentials);
|
||||
const sql = `
|
||||
SELECT table_name FROM information_schema.tables
|
||||
WHERE table_schema = '${credentials.database}'
|
||||
and table_name like '%${query || ''}%'
|
||||
ORDER BY table_name
|
||||
`;
|
||||
const [rows] = await connection.query(sql);
|
||||
const results = (rows as IDataObject[]).map(r => ({
|
||||
name: r.TABLE_NAME as string,
|
||||
value: r.TABLE_NAME as string,
|
||||
}));
|
||||
connection.end();
|
||||
return { results };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user