Skip to content

Commit

Permalink
🐛 add pg-format
Browse files Browse the repository at this point in the history
  • Loading branch information
benjlevesque committed Sep 27, 2024
1 parent ea6e574 commit 4119f39
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import format from 'pg-format';

import { Entity } from '@potentiel-domain/entity';
import { flatten } from '@potentiel-libraries/flat';
import { executeQuery } from '@potentiel-libraries/pg-helpers';
Expand All @@ -10,7 +12,6 @@ export const updateProjection = async <TProjection extends Entity>(
readModel: AtLeastOne<Omit<TProjection, 'type'>>,
): Promise<void> => {
const [updateQuery, values] = prepareUpdateProjectionQuery(readModel);
console.log(updateQuery, values);
await executeQuery(updateQuery, id, ...values);
};

Expand All @@ -26,7 +27,7 @@ export const prepareUpdateProjectionQuery = <TProjection extends Entity>(
the `i+2` operation is due to `i` starting at 0, and $1 being the key
*/
const jsonb_set = Object.keys(flatReadModel).reduce(
(acc, curr, i) => `jsonb_set(${acc},'{${curr}}',$${i + 2})`,
(acc, curr, i) => `jsonb_set(${acc},'{${format('%I', curr)}}',$${i + 2})`,
'value',
);
const values = Object.values(flatReadModel).map((value) =>
Expand Down

0 comments on commit 4119f39

Please sign in to comment.