Sequelize should be a peerDependency
kvindascr opened this issue · 4 comments
Hello,
First of all, thanks for all the great work on the plugin.
I have been facing an issue with the plugin and sequelize, in specific when using functions or literals with custom names.
The issue that I'm having is that I'm currently using Typescript / ES6 signature.
So to create my queries or apply a Sequelize function I use something like:
import { fn as seqFn, literal as seqLiteral } from 'sequelize';
...
const count = seqFn('json_array_length', seqCast(seqCol('mycol'), 'json'));
So first of all, in order to be able to implement that notation I need to install a version of sequelize in my package.json.
Now in general, pretty much everything works good, until I reached this blocker when using custom named attributes.
const query = {
attributes: [
"attr1", "attr2", "attr3"
[count, 'myCountResult'],
]
}
This creates a custom query attribute mapping for the function result.
Steps to reproduce the behavior:
- Im currently using Sails 0.12
- When and where error is happening
Now when that executes generates an exception specifically in the file.
node_modules/sails-hook-sequelize/node_module/sequelize/lib/dialects/abstract/query-generator.js
Specifically in line 1426 } else if (!attr[0].includes('(') && !attr[0].includes(')')) {
The issue in specific occurs before reaching to that line the following validation should have occured:
if (attr[0] instanceof Utils.SequelizeMethod) {
But as I have 2 instances of sequelize node_modules/sequelize
and node_modules/sails-hook-sequelize/node_modules/sequelize
then the reference to the class is not the same.
I have fixed this temporarily by modifying the Sails-hook-sequelize package.json and moving the sequelize
dependency as a peerDependency
.
In this way both sails-hook-sequelize and my app can share the same sequelize instance and version.
A clear and concise description of what the bug is.
- Error description
Expected behavior
I should be able to use ES6 syntax and not rely on globals.
Also I should be able to use custom function named attributes.
Desktop (please complete the following information):
- OS: Mac
- Node.js 10.15
- Sequelize version 5.21
Hi @kvindasAB ! Thanks!
Sorry for late answer.
Well, i understand you case, but this hook can't work without sequelize package so it MUST be declared as dependency. It's not a plugin, hook can't ignore it.
I suggest just import from a hook/node_modules/sequelize
package directly, like so:
import { fn as seqFn, literal as seqLiteral } from 'node_modules/sails-hook-sequelize/node_modules/sequelize';
You're welcome! Happy holidays! :)