Repository navigation
Closed
Labels
dialect: mysqlFor issues and PRs. Things that involve MySQL (and do not involve all dialects).type: featureDEPRECATED: replace with the "feature" issue type
Description
Issue Creation Checklist
[x ] I have read the contribution guidelines
Bug Description
Since Sequelize 6.5.0, there is FullText support, but it is based on Postgres which uses a completely different syntax from MySQL.
We used a hack before to get this working on MySQL, but, with the new version, that hack doesn't work anymore.
What do you expect to happen?
Before 6.5.0 work around
We use a searchText column for all our models with a FULLTEXT index applied.
What we want to add to the query:
Sequelize.literal(`MATCH (`Faq`.`searchText`) AGAINST(\'"test label" test* label*\' IN BOOLEAN MODE)`)The reason we add both "test" and test* is that we want to ensure "as you type" hit, but will get a preference for an exact match.
What is actually happening?
After the 6.5.0 upgrade, we use
searchText: {
[Op.match]: '"test label" test* label*',
},and this gets generated
`Faq`.`searchText` @@ \'\\"test\\" test* \\"label\\" label*\'which gets rejected by MySQL
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@@ '\\"test\\" test* \\"label\\" label*')' at line 1
Additional context
Environment
- Sequelize version: 6.13.0
- Node.js version: 16.13.1
- If TypeScript related: TypeScript version: 4.5.4
Bug Report Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- [x ] I think this problem happens only for the following dialect(s): MySQL
- I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don't know how to start, I would need guidance.
- [x ] No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
Metadata
Metadata
Assignees
Labels
dialect: mysqlFor issues and PRs. Things that involve MySQL (and do not involve all dialects).type: featureDEPRECATED: replace with the "feature" issue type
Activity
WikiRik commentedon Feb 4, 2022
So if I understand correctly you want the match operator to work for MySQL as well? Since I think that using Sequelize.literal() should still work in the latest version
mschipperheyn commentedon Feb 8, 2022
Actually no. On 16.15.1, I get an error:
Unfortunately, 6.4.0 where it still works is a bit of a nightmare in terms of typescript related issues. So, I guess I'm between a. rock and a hard place. Let me see how hard it would be to create a PR to just resolve this feature.
mschipperheyn commentedon Feb 14, 2022
@WikiRik
WikiRik commentedon Feb 16, 2022
Thanks for the ping. Unfortunately, I haven't had the time yet to look into this. Feel free to see if you can create a PR for this
ephys commentedon Feb 25, 2022
Supporting
literalinOp.matchis something I plan on doing with #14022 and #14020mschipperheyn commentedon Feb 28, 2022
@ephys let me know if I can be of assistance
ephys commentedon Feb 28, 2022
@mschipperheyn thanks :)
If you're willing, I'm looking for reviews on this PR #14022
Specifically the file
test/unit/sql/where.test.tsis the new suite of unit tests that tries to cover everything related to convertingWhereOptionsto a SQL string for the different dialects.Good thing you pinged me, too, because I forgot to test
Op.matchin MySQLOnce this PR is merged, I'll start fixing every failing unit test in #14020
A few disclaimers:
WHERE#14020 will only land in v7 as even with the new test suite, I'm afraid of introducing an incompatible change.MATCHwould be supported but we need to determine if its support is worth it or if improving literals would be a better approach:I think it may be better to do the second one as we'd be unable to properly support
MATCHwith the first approachmschipperheyn commentedon Mar 2, 2022
I'll have a look when I wake up
mschipperheyn commentedon Mar 5, 2022
Yeah, I think the second approach would be better. IT allows for more flexibility, but it should be easy to mix it in with other "regular" attribute filters
ephys commentedon Mar 7, 2022
Well doing something like
would not make sense, you can't compare an attribute to a literal ; we don't know where the attribute should go. If you want to combine it with other clauses, simply use
ororand:This also means this is already possible today. The
sql&attrfeatures would make it better but you can just do this today:The only thing we need to do (for this issue) is make sequelize throw with a clear error message when
Op.matchis used with the mysql dialectmschipperheyn commentedon Mar 7, 2022
@ephys Just to be clear:
is no longer possible since after 6.4.0. It throws Invalid value Literal
It also throws on ephys/fix-and-or-typing
ephys commentedon Mar 7, 2022
I've just tried it with mysql (db) 8.0, sequelize 6.14.0, mysql2 2.3.3 and it worked.
The following code:
resulted in
I also have a passing test in that PR for it (although not inside
and()):The only test that fails (for now) is this one https://github.com/sequelize/sequelize/pull/14022/files#diff-086a401f6323d954b7175bb6ba259f1bc895a24ee599ab2e9c4350b93e980d09R463, but it's not what you want as it would insert an extra
=operator:mschipperheyn commentedon Mar 9, 2022
I've tried various versions of sequelize versions after 6.4.0, including 6.14.0, 6.16.1 and the PR branch. All of them throw errors with my previously working Match code. So let me post here the code I'm using. Perhaps we have some error of alignment.
I almost always use
findAndCountAllby the wayI tried it with the
Op.and(...whereArray)style as well with the same result.ephys commentedon Mar 10, 2022
Still very strange, I couldn't reproduce the error with your code snippet either
I ran the following SSCCE locally:
and it gave me the output I was expecting:
It would really help me if you could create one that reproduces the problem (https://github.com/sequelize/sequelize-sscce)
mschipperheyn commentedon Mar 10, 2022
Ok, I will have a go at a reproduction. First of all I will do a fresh install and see if there isn't some kind of lingering issue there somehow. Oh wait a minute. We are using sequelize-typescript as an abstraction layer. That must be it somehow.
mschipperheyn commentedon Apr 1, 2022
This occurred because Sequelize exported from sequelize-typescript was used instead of Sequelize exported from sequelize itself.
ephys commentedon Apr 1, 2022
thanks for letting us know :)