question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sequelize.fn doesn't work with bind replacements if value has `$` in it

See original GitHub issue

Issue 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
Srklcommented, Nov 11, 2020

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\')')

4reactions
andrew8088commented, Oct 16, 2019

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found