Javascript Model.query()返回;“未定义”;错误

Javascript Model.query()返回;“未定义”;错误,javascript,node.js,sails.js,Javascript,Node.js,Sails.js,在Sailsjs控制台上,我试图使用Waterline/Sails的方法在MySQL数据库上执行原始SQL查询。但是,我一直收到错误消息: 运行Waterline的其他方法,如成功执行 sails> User.find().exec(console.log) undefined sails> null [ { email: 'xxxx', password: 'xxxxx', name: 'xxxx', }] 互联网搜索表明应使用sails-mysql适配器进行连

在Sailsjs控制台上,我试图使用Waterline/Sails的方法在MySQL数据库上执行原始SQL查询。但是,我一直收到错误消息:

运行Waterline的其他方法,如成功执行


sails> User.find().exec(console.log)
undefined
sails> null [ { email: 'xxxx',
    password: 'xxxxx',
    name: 'xxxx',
   }]
 
互联网搜索表明应使用sails-mysql适配器进行连接;这就是我正在使用的,问题仍然存在。

我的配置/connections.js文件


module.exports.connections = {
  default_dev_mysql_server: {
    adapter: 'sails-mysql',
    host: '127.0.0.1',
    port: 3306,
    user: 'xxxxx',
    password: 'xxxxx',
    database: 'xxxxxx'}
}
 

module.exports.models = {
  schema: true,
  connection: 'default_dev_mysql_server',
  migrate: 'safe'

};
 
我的配置/models.js文件


module.exports.connections = {
  default_dev_mysql_server: {
    adapter: 'sails-mysql',
    host: '127.0.0.1',
    port: 3306,
    user: 'xxxxx',
    password: 'xxxxx',
    database: 'xxxxxx'}
}
 

module.exports.models = {
  schema: true,
  connection: 'default_dev_mysql_server',
  migrate: 'safe'

};
 
我正在运行sails mysql v0.11.2和sails v0.11.2,这是该软件最稳定的版本

为了能够在SAILSJ上执行原始SQL查询,我还缺少哪些其他设置?谷歌并不是很有帮助


谢谢。

exec
在使用ORM功能时是必需的,因为在内部,它构建了一个SQL语句,以便在以后的阶段进行剪切<另一方面,code>query接受字符串SQL语句和回调作为其参数,并且不使用
exec
,因此其未定义。请尝试以下方法:

User.query('SELECT id from user', function(err, res){
  console.log(err, res);
});

哇!如果我更加注意这些示例,我实际上可以看到exec()没有与query()一起使用,而用于其他功能。非常感谢你的帮助。