diff --git a/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/operations.js b/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/operations.js index 9e3302756d..b7e6ab2642 100644 --- a/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/operations.js +++ b/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/operations.js @@ -2,12 +2,25 @@ import { tooljetDatabaseService } from '@/_services'; import { isEmpty } from 'lodash'; import PostgrestQueryBuilder from '@/_helpers/postgrestQueryBuilder'; import { resolveReferences } from '@/_helpers/utils'; +import { hasEqualWithNull } from './util'; export const tooljetDbOperations = { perform, }; async function perform(queryOptions, organizationId, currentState) { + const hasNullWithEqual = hasEqualWithNull(queryOptions); + // SQL does not support equal operation with null value, so let's handle it here. + if (hasNullWithEqual) { + return { + status: 'failed', + statusText: 'failed', + message: 'Query can not run, because app can not perform equal operation with null value', + description: 'Please use IS operator with the null value comparision.', + data: {}, + }; + } + switch (queryOptions.operation) { case 'list_rows': return listRows(queryOptions, organizationId, currentState); diff --git a/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/util.js b/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/util.js new file mode 100644 index 0000000000..aea8b9f462 --- /dev/null +++ b/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/util.js @@ -0,0 +1,36 @@ +import { get } from 'lodash'; +/** + * Checks if the queryOptions object contains a filter with an 'eq' (equal) operator and a value equal to '{{null}}'. + * + * @function hasEqualWithNull + * @param {Object} queryOptions - The query options object to check for the presence of the specified filter. + * @property {Object} queryOptions.list_rows.where_filters - An object containing the filters to be checked. + * @returns {boolean} - Returns true if the specified filter is found, false otherwise. + * + * @example + * const queryOptions = { + * list_rows: { + * where_filters: { + * filter1: { + * operator: 'eq', + * value: '{{null}}', + * }, + * }, + * }, + * }; + * + * const result = hasEqualWithNull(queryOptions); // true + */ +export const hasEqualWithNull = (queryOptions) => { + const filters = get(queryOptions, 'list_rows.where_filters'); + if (filters) { + const filterKeys = Object.keys(filters); + for (let i = 0; i < filterKeys.length; i++) { + const filter = filters[filterKeys[i]]; + if (filter.operator === 'eq' && filter.value === '{{null}}') { + return true; + } + } + } + return false; +};