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

Support Set as bind parameter #477

Open
tv42 opened this issue Mar 29, 2024 · 1 comment
Open

Support Set as bind parameter #477

tv42 opened this issue Mar 29, 2024 · 1 comment

Comments

@tv42
Copy link

tv42 commented Mar 29, 2024

Is your feature request related to a problem? Please describe.

I tried to pass a Set as a bind parameter, expecting it to behave like Array. It was hard to debug since the query gave wrong results, not an error.

Describe the solution you'd like

Support Set just like Array: convert it to a Postgres array.

Additional context

Set:

$ deno eval 'import { Client } from "https://deno.land/x/[email protected]/mod.ts"; const client = new Client({}); await client.connect(); const odds = new Set([1,3,5]); const result = await client.queryObject`SELECT 3=ANY(${odds}) AS should_be_true`; console.log(result.rows);'
[ { should_be_true: false } ]

Array:

$ deno eval 'import { Client } from "https://deno.land/x/[email protected]/mod.ts"; const client = new Client({}); await client.connect(); const odds = new Array([1,3,5]); const result = await client.queryObject`SELECT 3=ANY(${odds}) AS should_be_true`; console.log(result.rows);'
[ { should_be_true: true } ]
@tv42 tv42 changed the title Support Set as bind parameters Support Set as bind parameter Mar 29, 2024
@tv42
Copy link
Author

tv42 commented Mar 29, 2024

This seems like a very simple change (but I haven't actually tested this):

postgres/query/encode.ts

Lines 98 to 99 in 2606e50

} else if (value instanceof Array) {
return encodeArray(value);

add

  } else if (value instanceof Set) {
    return encodeArray(Array.from(value));

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