Sequelize.fn doesn't work with bind replacements if value has `$` in it
See original GitHub issueIssue Description
What are you doing?
I’m inserting a record and using a database function (like upper
) to format a field with a $
in it.
Here is the link to the SSCCE for this issue: https://github.com/papb/sequelize-sscce/pull/11
// more details in the link above
const User = sequelize.define('User', {
name: DataTypes.TEXT
});
await User.create({
name: sequelize.fn('upper', '$user3')
});
What do you expect to happen?
I expect to successfully insert the record.
What is actually happening?
I get the error:
Named bind parameter "$user3" has no value in the given object.
Additional context
Add any other context or screenshots about the feature request here.
Environment
- Sequelize version: 5.16.0
- Node.js version: 10.15.0
- Operating System: MacOS X, Linux
Issue Template Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time but I don’t know how to start, I would need guidance.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Sequelize: Unhandled rejection Error: Both `replacements ...
In Sequelize (REST API on EXPRESS) only in POST (CREATE) request, i calling API Route which call function from controller where I use: ......
Read more >Raw Queries - Sequelize
Bind parameters are like replacements. Except replacements are escaped and inserted into the query by sequelize before the query is sent to the ......
Read more >Parameters not being replaced - Google Groups
Hi, I have been using sequelize for the past two months and haven't encountered any serious problems but I've been stuck with this...
Read more >Raw queries - Manual | Sequelize
Bind parameters are like replacements. Except replacements are escaped and inserted into the query by sequelize before the query is sent to the...
Read more >How To Use Sequelize with Node.js and MySQL - DigitalOcean
Sequelize is a Node.js-based Object Relational Mapper that makes it easy to work with MySQL, MariaDB, SQLite, PostgreSQL databases, and more ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Similar problem here using the function JSON_EXTRACT.
The call
sequelize.fn('JSON_EXTRACT', db.sequelize.col('custom_fields'), '$.F01')
The loggs show that it is translated to:
JSON_EXTRACT('custom_fields', '$$.F01')
All the MySQL functions that deal with JSON objects use the symbol $ to identify the key of the object. Because Sequelize adds an extra $ to the query, none of the functions can be used.
The alternative that I found is to use a literal instead:
sequelize.literal('JSON_EXTRACT(custom_fields, \'$.F01\')')
@papb Thanks, I’ll take a stab at this early next week!
@zacharysierakowski I can see what you’re saying … I’m gonna give it a try, just for fun, whether or not it ends up in the codebase.