Reputation: 1400
In sails console, I should be able to:
User.query("SELECT * FROM USER")
But I get undefined is not a function
, meaning .query
is undefined.
I've reinstalled/updated sails and waterline, as well as sails globally and I still get the same error.
Thanks!
Upvotes: 1
Views: 1335
Reputation: 1
If you using local.js to set env.
Check env name, it should be small letters.
EX:- environment: process.env.NODE_ENV || 'development'
I got same issue my env name was 'Development', changed to 'development' and working fine.
Upvotes: 0
Reputation: 325
First you should verify your conection
#model
module.exports.connections = {
localMysql: {
adapter: 'sails-mysql',
user: 'root',
host: 'localhost',
database: 'someDbase'
},
if you run for example
#EXAMPLE
User.find().exec(function (error, res){
console.log(res)
});
this return all users, later If you don't run .exec(), your query will not execute.
here you need a callback:
#CONTROLLER
User.query("SELECT * FROM USER", function(err, results) {
if (err)
return res.serverError(err);
return res.ok(results);
});
Upvotes: 0
Reputation: 1400
Solved it. Sails documentation indicates using:
{
...
adapter: 'sails-postgresql',
...
}
But sails-postgresql is still using the older:
{
...
module: 'sails-postgresql',
...
}
Once I changed that I started seeing queries come through the server and the query
function became defined under the model I created.
Upvotes: 2
Reputation: 2476
How did you configured the model User? Which adapter is it using?
.query method is only allowed when using an SQL adapter.
Upvotes: 1