Open arrafi-ahmed opened 2 months ago
Trying to build partial query while working with jsonb, but its printing string in inserted row:
exports.updateEntityLastCount = async ({ pairs, tournamentId }) => { const keys = Object.keys(pairs); const vals = Object.values(pairs).map( (value, index) => ((entity_last_count ->> ${keys[index]})::int + ${value})::text, ); const keyArray = sql${keys.join(", ")}; const valArray = sql${vals.join(", ")};
((entity_last_count ->> ${keys[index]})::int + ${value})::text
${keys.join(", ")}
${vals.join(", ")}
return sql UPDATE tournaments SET entity_last_count = entity_last_count || jsonb_object( ARRAY[${keyArray}], ARRAY[${valArray}]) WHERE id = ${tournamentId};; };
UPDATE tournaments SET entity_last_count = entity_last_count || jsonb_object( ARRAY[${keyArray}], ARRAY[${valArray}]) WHERE id = ${tournamentId};
DB inserted row: {"group": 1, "match": 1, "phase": "((entity_last_count ->> phase)::int + 1)::text", "bracket": 1}
Trying to build partial query while working with jsonb, but its printing string in inserted row:
exports.updateEntityLastCount = async ({ pairs, tournamentId }) => { const keys = Object.keys(pairs); const vals = Object.values(pairs).map( (value, index) =>
((entity_last_count ->> ${keys[index]})::int + ${value})::text
, ); const keyArray = sql${keys.join(", ")}
; const valArray = sql${vals.join(", ")}
;return sql
UPDATE tournaments SET entity_last_count = entity_last_count || jsonb_object( ARRAY[${keyArray}], ARRAY[${valArray}]) WHERE id = ${tournamentId};
; };DB inserted row: {"group": 1, "match": 1, "phase": "((entity_last_count ->> phase)::int + 1)::text", "bracket": 1}