epilogue icon indicating copy to clipboard operation
epilogue copied to clipboard

Raw SQL with sequelize?

Open omayhemo opened this issue 8 years ago • 7 comments

Is it possible to use the raw sql options built into sequelize, through epilogue?

omayhemo avatar Aug 19 '16 13:08 omayhemo

@omayhemo with milestones you can essentially do whatever you want, can you be more specific?

mbroadst avatar Aug 19 '16 13:08 mbroadst

We have a very complex query, with wildcards. In our query we need to be able to use the sql underscore wild card.

https://msdn.microsoft.com/en-us/library/ms179859.aspx

Thus far, I haven't found a way to do that through the normal epilogue criteria filter. My first inclination is to use sequalize raw queries.

http://docs.sequelizejs.com/en/latest/docs/raw-queries/

If it's possible to filter in this manner without gaining direct access to sequelize (through epilogue), I'm very happy to implement it that way. Failing that option, I need to handle the query explicitly.

omayhemo avatar Aug 19 '16 13:08 omayhemo

@omayhemo maybe this tip would help you: https://github.com/dchester/epilogue/issues/167#issuecomment-223343235 ?

mbroadst avatar Aug 19 '16 14:08 mbroadst

Thanks for your response. Given that I hook into before list fetch and add the raw:true option to context.options, where then do I pass the raw sql, on the criteria?

omayhemo avatar Aug 19 '16 15:08 omayhemo

oh right I see what you're saying. no, presently we don't have any way of setting some sort of option to execute a sequelize.query("raw data in here"). You have two options:

  • simply create a milestone before the implemented milestone for your controller (e.g. the milestone for Create is write), put your query into that milestone and then skip the rest of the action.
  • we could technically support some sort of option in context, but it would be tricky and controller specific.

The first option is the most flexible choice. If you'd like to experiment with the latter option we would need more information, maybe even a model definition and an example of what kinds of output you're looking for.

mbroadst avatar Aug 19 '16 15:08 mbroadst

So I can't cast raw sequel to the context.query ? What is the raw option for, then?

And what do you mean skip the rest of the action? Can you give me an example?

omayhemo avatar Aug 19 '16 15:08 omayhemo

no, in fact I don't believe context.query is a thing.

according to do the docs, the raw option does the following:

[options.raw=false] Boolean If set to true, values will ignore field and virtual setters.

for building, and:

[options.raw]   Boolean Return raw result. See sequelize.query for more information.

for querying

mbroadst avatar Aug 19 '16 15:08 mbroadst