Spaces:
Build error
Build error
File size: 855 Bytes
d9494a5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | export const createSqlWhereTupleInClause = (
conditions: [string, string][][],
tableName: string,
) => {
const fieldNames = conditions[0].map(([field, _]) => field);
const tupleClause = fieldNames
.map((field) => `"${tableName}"."${field}"`)
.join(', ');
const valuePlaceholders = conditions
.map((_, index) => {
const placeholders = fieldNames.map(
(_, fieldIndex) => `:value${index}_${fieldIndex}`,
);
return `(${placeholders.join(', ')})`;
})
.join(', ');
const clause = `(${tupleClause}) IN (${valuePlaceholders})`;
const parameters: Record<string, string> = {};
conditions.forEach((condition, conditionIndex) => {
condition.forEach(([_, value], fieldIndex) => {
parameters[`value${conditionIndex}_${fieldIndex}`] = value;
});
});
return { clause, parameters };
};
|