mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-15 17:14:05 -08:00
add case insensitive search to "search" action
This commit is contained in:
parent
4f8be47b43
commit
03594050f1
|
@ -52,6 +52,20 @@ export const rowSearchDescription: RowProperties = [
|
|||
default: '',
|
||||
description: 'What to look for?',
|
||||
},
|
||||
{
|
||||
displayName: 'Case Insensitive Search',
|
||||
name: 'insensitive',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['row'],
|
||||
operation: ['search'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description:
|
||||
'FALSE: The search distinguish between uppercase and lowercase characters. TRUE: Search ignores case sensitivity.',
|
||||
},
|
||||
{
|
||||
displayName: 'Activate wildcard search',
|
||||
name: 'wildcard',
|
||||
|
|
|
@ -13,30 +13,22 @@ export async function search(
|
|||
): Promise<INodeExecutionData[]> {
|
||||
const tableName = this.getNodeParameter('tableName', index) as string;
|
||||
const searchColumn = this.getNodeParameter('searchColumn', index) as string;
|
||||
const searchTerm = this.getNodeParameter('searchTerm', index) as any; // string or integer
|
||||
let searchTerm = this.getNodeParameter('searchTerm', index) as any; // string or integer
|
||||
const insensitive = this.getNodeParameter('insensitive', index) as boolean;
|
||||
const wildcard = this.getNodeParameter('wildcard', index) as boolean;
|
||||
const simple = this.getNodeParameter('simple', index) as boolean;
|
||||
|
||||
// get collaborators
|
||||
const collaborators = await getBaseCollaborators.call(this);
|
||||
|
||||
//let metadata: IDtableMetadataColumn[] = [];
|
||||
//let rows: IRow[];
|
||||
//let sqlResult: IRowResponse;
|
||||
|
||||
// get the collaborators (avoid executing this multiple times !!!!)
|
||||
/*let collaboratorsResult: ICollaboratorsResult = await seaTableApiRequest.call(
|
||||
this,
|
||||
{},
|
||||
'GET',
|
||||
'/dtable-server/api/v1/dtables/{{dtable_uuid}}/related-users/',
|
||||
);
|
||||
let collaborators: ICollaborator[] = collaboratorsResult.user_list || [];
|
||||
*/
|
||||
|
||||
// this is the base query. The WHERE has to be finalized...
|
||||
let sqlQuery = `SELECT * FROM \`${tableName}\` WHERE \`${searchColumn}\``;
|
||||
|
||||
if (insensitive) {
|
||||
searchTerm = searchTerm.toLowerCase();
|
||||
sqlQuery = `SELECT * FROM \`${tableName}\` WHERE lower(\`${searchColumn}\`)`;
|
||||
}
|
||||
|
||||
if (wildcard && isNaN(searchTerm)) sqlQuery = sqlQuery + ' LIKE "%' + searchTerm + '%"';
|
||||
else if (!wildcard && isNaN(searchTerm)) sqlQuery = sqlQuery + ' = "' + searchTerm + '"';
|
||||
else if (wildcard && !isNaN(searchTerm)) sqlQuery = sqlQuery + ' LIKE %' + searchTerm + '%';
|
||||
|
|
Loading…
Reference in a new issue