1
votes

I am working with a sails application that uses Sequelize as the ORM tool. Initial integration between the app and Sequelize was established via the sails-hook-sequelize plugin which can be found here. This approach has worked great so far, no problem defining and using models.

However, I hit a road block when I wanted to define a View as a Sequelize object. Sequelize doesn't (yet) have an easy way to do this. The work around I found was to execute a raw query and populate a table with the result.

Now I come to the second road block and the actual question itself. How do I simply execute a sequelize.query inside of my sails application? In stand alone node apps using sequelize I don't have a problem. However, this sails application has gotten away from me to the point where I'm not sure what object to actually call .query from! What I'm looking for is something simple like

Sequelize.query("SELECT * FROM `Document.MyView`", { type: Sequelize.QueryTypes.SELECT})

Sadly the above gives me sequelize.query is not a function

I have a connections.coffee file where the database connection is defined. It is named 'Core', however when I try Core.query I get Core is undefined

Seems like I am missing something simple and fundamental from stacking too many things on top of the other.

1

1 Answers

1
votes

Alright my problems arose from the sails-hook-sequelize plugin. Luckily my answer came from that plugin as well!

"sequelize" is a global in this plugin. So don't add a sequelize = require 'sequelize'. simply call the raw query with sequelize.query as expected (case sensitive).

Then your raw query should work! Thanks from past me.