Skip to content

Commit 92d9093

Browse files
committed
fix(dataapi): allow to perform searching with IN on empty arrays (like x in []), at least for string/text fields
1 parent df9527c commit 92d9093

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

adminforth/dataConnectors/baseConnector.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77

88

99
import { suggestIfTypo } from "../modules/utils.js";
10-
import { AdminForthFilterOperators, AdminForthSortDirections } from "../types/Common.js";
10+
import { AdminForthDataTypes, AdminForthFilterOperators, AdminForthSortDirections } from "../types/Common.js";
11+
import { randomUUID } from "crypto";
1112

1213

1314
export default class AdminForthBaseConnector implements IAdminForthDataSourceConnectorBase {
@@ -121,8 +122,14 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
121122
return { ok: false, error: `Value for operator '${filters.operator}' should be an array, in filter object: ${JSON.stringify(filters) }` };
122123
}
123124
if (filters.value.length === 0) {
124-
// nonsense
125-
return { ok: false, error: `Filter has IN operator but empty value: ${JSON.stringify(filters)}` };
125+
// nonsense, and some databases might not accept IN []
126+
const colType = resource.dataSourceColumns.find((col) => col.name == (filters as IAdminForthSingleFilter).field)?.type;
127+
if (colType === AdminForthDataTypes.STRING || colType === AdminForthDataTypes.TEXT) {
128+
filters.value = [randomUUID()];
129+
return { ok: true, error: `` };
130+
} else {
131+
return { ok: false, error: `Value for operator '${filters.operator}' should not be empty array, in filter object: ${JSON.stringify(filters) }` };
132+
}
126133
}
127134
filters.value = filters.value.map((val: any) => this.setFieldValue(fieldObj, val));
128135
} else {

0 commit comments

Comments
 (0)