You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Raw query with named substitution parameters gets quoted parameters #4494
good first issueFor issues. An issue that is a good choice for first-time contributors.status: understoodFor issues. Applied when the issue is understood / reproducible.type: featureDEPRECATED: replace with the "feature" issue type
This change would also not make a lot of room for introducing proper prepared queries later, perhaps a different identifier than : for tables/identifiers? Not sure what other libraries do for this type of stuff? Some research might be warranted.
I do remember we previously had support for using ?? as unescaped with unnamed replacement - but that won't work since :: has a different meaning in postgres
This is a pretty uncommon use case (I think), and I am not sure if this needs to be implemented at all. I've currently worked around this using Mustache, and it works just fine. The documentation should definitely be updated to point this out though.
From what I get, we need some way to escape from quoting. I wasn't explicitly referring to col I was referring to the pattern. we can add a feature like: sequelize.unquote('tableOrColumnOrFunction') that we can use like:
@subjectix Actually we already have sequelize.literal which might be usefull here - we'd just need to implement support for that in the format method then
On Mon, Apr 5, 2021, 10:37 AM guhkun13 ***@***.***> wrote:
i think i found it.
You can combine between backquote string and double string.
the problem arise when you replace table name, so my solution is how to
make it not replaced.
Example :
table_name = 'users'
db.default.query(
SELECT name FROM ${table_name} ` +
" WHERE age= :age"
{
replacements: {
age: 24,
},
type: QueryTypes.SELECT,
}
)
noted that i use backquote `` until FROM table_name part, and the rest i
used doubel quote like usual.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4494 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA4NZFHWS6SX3JCHBSPK64TTHHYLZANCNFSM4BPSYAMQ>
.
Reacted by Arjan, Luke Watts, Damilola Emmanuel Olowookere and Peter
really appreciate the reminder,
and so, is there any safe solution ?
[update]
so my new approach is using conditional statement, to call another function that corresponds to the table name, so i avoid using raw query as sugggested.
i think it's more "micro", and dynamic enough to add custom things on the corresponds function.
but then,
I need to do something like :
" select * from users where email = 'something' and id not in (select user_id from users_banned) "
i did not find (yet) how to do this without using raw sql...
any help would be very appreciated
For those wandering souls just like me, I manually escaped them like so :'(
First I check if the column my user want to order is valid
If valid interpolate it in the query string else throw an error
const{ Sequelize }=require('sequelize');constsequelize=newSequelize('postgres://postgres:postgres@localhost:5432/test_db');constorderByColumn='username';constcolumns=Object.keys(Agent.rawAttributes);constisColumnPartOfModel=columns.indexOf(orderByColumn)!=-1;if(!isColumnPartOfModel){thrownewError('Unknown column');}constorderByDirection='ASC';constvalidDirections=['ASC','DESC'];if(orderByDirection.indexOf(orderByDirection)===-1){thrownewError('Ordering direction is not valid');}sequelize.query(`SELECT * FROM players ORDER BY ${orderByColumn}${orderByDirection}`);
for the steps, i prefer to separate the process of validation and actions (controller).
using middleware to validate input (im using express-validator); columnName, orderDirection, etc.
by doing that, controller only accept 'validated data'
then in controller, u can query it in ORM way. in my experience, it's a bit faster than using raw query (cmiiw)
@czardoz - Is this issue still "up for grabs"? It's been open for awhile and it would be cool for me to have my first issue be something that's both older and seemingly impactful. Please let me know!
good first issueFor issues. An issue that is a good choice for first-time contributors.status: understoodFor issues. Applied when the issue is understood / reproducible.type: featureDEPRECATED: replace with the "feature" issue type
Activity
janmeier commentedon Sep 16, 2015
This is not possible currently
First we'd need to come up with a syntax for this - any suggestions @czardoz ?
czardoz commentedon Sep 16, 2015
Coming up with new syntax might not be necessary.
Something like this should work too:
Edit: Apologies for the bad formatting, I'm typing on my phone
janmeier commentedon Sep 16, 2015
Yeah, that coudl work as well :)
PR welcome
mickhansen commentedon Sep 17, 2015
Hmm, but the value of
tableNamecould be a JSON object that needs to be inserted as JSON.We probably want to use
$prefixed keys.mickhansen commentedon Sep 17, 2015
This change would also not make a lot of room for introducing proper prepared queries later, perhaps a different identifier than
:for tables/identifiers? Not sure what other libraries do for this type of stuff? Some research might be warranted.janmeier commentedon Sep 17, 2015
I do remember we previously had support for using
??as unescaped with unnamed replacement - but that won't work since::has a different meaning in postgresczardoz commentedon Sep 17, 2015
This is a pretty uncommon use case (I think), and I am not sure if this needs to be implemented at all. I've currently worked around this using Mustache, and it works just fine. The documentation should definitely be updated to point this out though.
alitaheri commentedon Oct 13, 2015
guys come on, don't we already have a familiar syntax for this:
sequelize.col('deleted')😁janmeier commentedon Oct 13, 2015
@subjectix Quoting columns is not the issue - its not quoting everything else
alitaheri commentedon Oct 13, 2015
From what I get, we need some way to escape from quoting. I wasn't explicitly referring to
colI was referring to the pattern. we can add a feature like:sequelize.unquote('tableOrColumnOrFunction')that we can use like:The unquote function will return an instance of a function we can check with
instanceofand not quote the result if it'sstringonly sanitize it.janmeier commentedon Oct 20, 2015
@subjectix Actually we already have
sequelize.literalwhich might be usefull here - we'd just need to implement support for that in the format method thenalitaheri commentedon Oct 20, 2015
Good idea! I didn't know that 😁
eraye1 commentedon Apr 8, 2016
Is there a solution to this?
12 remaining items
robin-dunn commentedon Dec 24, 2019
Would also like to see this feature implemented.
repodevs commentedon Jun 13, 2020
Is there anyone working on this issue?
aayushmall commentedon Jul 17, 2020
Any update on this issue, as I also need something like this with sequelize, having dynamic table names from the input.
guhkun13 commentedon Apr 5, 2021
think I found it . You can combine between backquote string and double string
Example :
table_name = 'users'
db.default.query( `SELECT name FROM ${table_name} ` + " WHERE age= :age" { replacements: { age: 24, }, type: QueryTypes.SELECT, } )noted that i use backquote `` until FROM table_name part, and the rest i used double quote like usual.
czardoz commentedon Apr 5, 2021
guhkun13 commentedon Apr 6, 2021
really appreciate the reminder,
and so, is there any safe solution ?
[update]
so my new approach is using conditional statement, to call another function that corresponds to the table name, so i avoid using raw query as sugggested.
i think it's more "micro", and dynamic enough to add custom things on the corresponds function.
but then,
I need to do something like :
" select * from users where email = 'something' and id not in (select user_id from users_banned) "
i did not find (yet) how to do this without using raw sql...
any help would be very appreciated
meSmashsta commentedon Apr 28, 2021
Guys, it's 2021, where are we with this? :'(
meSmashsta commentedon Apr 28, 2021
For those wandering souls just like me, I manually escaped them like so :'(
guhkun13 commentedon Apr 29, 2021
for the steps, i prefer to separate the process of validation and actions (controller).
by doing that, controller only accept 'validated data'
AZS-99 commentedon Aug 24, 2021
Almost 7 years and still nothing .... Any update on this apart from the cricket in the background?
rscottlundgren commentedon Aug 9, 2022
@czardoz - Is this issue still "up for grabs"? It's been open for awhile and it would be cool for me to have my first issue be something that's both older and seemingly impactful. Please let me know!
ephys commentedon Oct 3, 2022
Feature #14299 should be able to cover the use cases discussed in this issue:
Villva-vinoth commentedon Nov 25, 2024
await sequelize.query(
create role :username,{type:QueryTypes.RAW,
replacements:{username:data.user_name},
transaction
})
Is there any body help to fix this
create role 'admin'
i m still getting the issue quote and thanks in advance