ArChak
ArChak
Explore posts from servers
DTDrizzle Team
Created by ArChak on 7/5/2024 in #help
How to check user input is a valid column before appending condition?
Does anyone knows the proper way to do so?
if (columnFilters.length > 0) {
const columnWhereClause: (SQL | undefined)[] = columnFilters.map(
(filter) => {
const columns = getTableColumns(tasks);

if (filter.column in columns) {
// getting error on columns[filter.column]: type 'string' can't be used to index type
return ilike(columns[filter.column], `%${filter.keyword}%`);
}
},
);
whereClause.push(and(...columnWhereClause));
}
if (columnFilters.length > 0) {
const columnWhereClause: (SQL | undefined)[] = columnFilters.map(
(filter) => {
const columns = getTableColumns(tasks);

if (filter.column in columns) {
// getting error on columns[filter.column]: type 'string' can't be used to index type
return ilike(columns[filter.column], `%${filter.keyword}%`);
}
},
);
whereClause.push(and(...columnWhereClause));
}
4 replies