Skip to content
Advertisement

error on sequelize raw query: query is not a function

I’m trying to use raw queries from sequelize in an express app. My folder structure is:

JavaScript

I want to use sequelize which I already define in /models/index.js from a controller.

This is /models/index.js:

JavaScript

I want to use a raw query in my price controller:

JavaScript

But I’m getting this error message:

JavaScript

How can I fix this?

Advertisement

Answer

The Sequelize library is being assigned to a variable on the db object.

The error is in the second file instead of calling

JavaScript

We should call

JavaScript

In the first case we have called a function that does not exist. In another case we could assign the query function to a property on the db object.

JavaScript

or you can de-structure using ES6

JavaScript

Now we can run db.query as expected.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement