Connect logic in Workspace Entity Manager (#13078)
Large PR, sorry for that. Don't hesitate to reach me to have full context (env. 500lines for integration and unit tests) - Add connect logic in Workspace Entity Manager - Update QueryDeepPartialEntity type to enable dev to use connect - Add integration test on createOne / createMany - Add unit test to cover main utils - Remove feature flag on connect closes https://github.com/twentyhq/core-team-issues/issues/1148 closes https://github.com/twentyhq/core-team-issues/issues/1147
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
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 };
|
||||
};
|
||||
Reference in New Issue
Block a user