add case insensitive search to "search" action

This commit is contained in:
Christoph Dyllick-Brenzinger 2023-12-15 15:55:19 +01:00
parent 4f8be47b43
commit 03594050f1
2 changed files with 21 additions and 15 deletions

View file

@ -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',

View file

@ -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 + '%';