-
Notifications
You must be signed in to change notification settings - Fork 303
extra dynamic queries #244
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
Comments
Besides the |
Hey there 🙂 Dynamically composing sql like that is not possible yet, but I've got a plan outlined and the progress is tracked in #12 The reason it's not simply concatenating strings is because I want to prevent accidental sql injection. Usually there are ways of achieving it without resolving to const key = "yay"; // or null
const result = await sql`
SELECT * from ahoy
WHERE 1 = 1 and (${ key } is null or key = ${ key })
` |
hi, your example is giving me:
am I missing anything? |
|
Ah ok. Out of curiosity what type is the ahoy_key column in your example? |
it was just a character varying.
was also fine, with |
Ah alright, thanks 👍 |
well, thank you kind sir :) Here's the complete snippet for the future trouble maker: const key = "/2212" || null;
//const key = false || null;
const result = await sql`
SELECT * from ahoy
WHERE 1 = 1
and (${key}::text is null or ahoy_key = ${key})
`; |
I've got a query with this: WHERE lower(tt.tags::text)::text[] @> ${sql.array(tags)} It works great when there's a tag string or more in the array. But when
Would really like to avoid |
Hey! This worked: WHERE lower(tt.tags::text)::text[] @> ${sql.array(tags)}
OR ${sql.array(tags)} = '{}' |
Hi again :)
Could you please advise the possibility of achieving this? or if it at all feasible to do?
The text was updated successfully, but these errors were encountered: