Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial query build giving string output #945

Open
arrafi-ahmed opened this issue Sep 16, 2024 · 0 comments
Open

Partial query build giving string output #945

arrafi-ahmed opened this issue Sep 16, 2024 · 0 comments

Comments

@arrafi-ahmed
Copy link

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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant