mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(core): Support filtering Data Table getManyRows on null (no-changelog) (#18730)
This commit is contained in:
@@ -2937,5 +2937,77 @@ describe('dataStore', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
it('retrieves supports filter by null', async () => {
|
||||
// ARRANGE
|
||||
const { id: dataStoreId } = await dataStoreService.createDataStore(project1.id, {
|
||||
name: 'dataStore',
|
||||
columns: [
|
||||
{ name: 'c1', type: 'string' },
|
||||
{ name: 'c2', type: 'boolean' },
|
||||
],
|
||||
});
|
||||
|
||||
const rows = [
|
||||
{ c1: null, c2: true },
|
||||
{ c1: 'Marco', c2: true },
|
||||
{ c1: null, c2: false },
|
||||
{ c1: 'Polo', c2: false },
|
||||
];
|
||||
|
||||
const ids = await dataStoreService.insertRows(dataStoreId, project1.id, rows);
|
||||
expect(ids).toEqual([1, 2, 3, 4].map((id) => ({ id })));
|
||||
|
||||
// ACT
|
||||
const result = await dataStoreService.getManyRowsAndCount(dataStoreId, project1.id, {
|
||||
filter: {
|
||||
type: 'and',
|
||||
filters: [{ columnName: 'c1', condition: 'eq', value: null }],
|
||||
},
|
||||
});
|
||||
|
||||
// ASSERT
|
||||
expect(result.count).toEqual(2);
|
||||
// Assuming IDs are auto-incremented starting from 1
|
||||
expect(result.data).toMatchObject([
|
||||
{ c1: null, c2: true, id: 1 },
|
||||
{ c1: null, c2: false, id: 3 },
|
||||
]);
|
||||
});
|
||||
it('retrieves supports filter by not null', async () => {
|
||||
// ARRANGE
|
||||
const { id: dataStoreId } = await dataStoreService.createDataStore(project1.id, {
|
||||
name: 'dataStore',
|
||||
columns: [
|
||||
{ name: 'c1', type: 'string' },
|
||||
{ name: 'c2', type: 'boolean' },
|
||||
],
|
||||
});
|
||||
|
||||
const rows = [
|
||||
{ c1: null, c2: true },
|
||||
{ c1: 'Marco', c2: true },
|
||||
{ c1: null, c2: false },
|
||||
{ c1: 'Polo', c2: false },
|
||||
];
|
||||
|
||||
const ids = await dataStoreService.insertRows(dataStoreId, project1.id, rows);
|
||||
expect(ids).toEqual([1, 2, 3, 4].map((id) => ({ id })));
|
||||
|
||||
// ACT
|
||||
const result = await dataStoreService.getManyRowsAndCount(dataStoreId, project1.id, {
|
||||
filter: {
|
||||
type: 'and',
|
||||
filters: [{ columnName: 'c1', condition: 'neq', value: null }],
|
||||
},
|
||||
});
|
||||
|
||||
// ASSERT
|
||||
expect(result.count).toEqual(2);
|
||||
// Assuming IDs are auto-incremented starting from 1
|
||||
expect(result.data).toMatchObject([
|
||||
{ c1: 'Marco', c2: true, id: 2 },
|
||||
{ c1: 'Polo', c2: false, id: 4 },
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -51,6 +51,15 @@ function getConditionAndParams(
|
||||
const paramName = `filter_${index}`;
|
||||
const column = `${quoteIdentifier('dataStore', dbType)}.${quoteIdentifier(filter.columnName, dbType)}`;
|
||||
|
||||
if (filter.value === null) {
|
||||
switch (filter.condition) {
|
||||
case 'eq':
|
||||
return [`${column} IS NULL`, {}];
|
||||
case 'neq':
|
||||
return [`${column} IS NOT NULL`, {}];
|
||||
}
|
||||
}
|
||||
|
||||
switch (filter.condition) {
|
||||
case 'eq':
|
||||
return [`${column} = :${paramName}`, { [paramName]: filter.value }];
|
||||
|
||||
Reference in New Issue
Block a user