Partial query build giving string output
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
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}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the exports.updateEntityLastCount entry point and reproduce the UPDATE against the jsonb entity_last_count column. Trace how the partial query values become the ARRAY arguments to jsonb_object, then verify that the phase value is stored as a number rather than the query expression text.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100