Context : Large PR with 600+ test files. Enable connect and disconnect logic in createMany (upsert true) / updateOne / updateMany resolvers - Add disconnect logic - Gather disconnect and connect logic -> called relation nested queries - Move logic to query builder (insert and update one) with a preparation step in .set/.values and an execution step in .execute - Add integration tests Test : - Test API call on updateMany, updateOne, createMany (upsert:true) with connect/disconnect
32 lines
855 B
TypeScript
32 lines
855 B
TypeScript
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 };
|
|
};
|