我正在尝试使“ Prepared Statement Example”正常工作(http://sailsjs.org/documentation/reference/waterline-orm/models/query),但我仅收到“ Error:ER_EMPTY_QUERY:查询为空”

这是我尝试过的:

day: function(req, res, next) {
  Lampo1.query({
    text: 'SELECT id FROM lampo WHERE node = $1',
    values: [ "node1" ]
  }, function(err, lampo1) {
    if (err) return res.serverError(err);
    return res.json(lampo1);
  });
},


因此,我尝试进行查询并将值添加为参数,但似乎根本不会生成查询。来自上面链接的基本示例查询有效。

最佳答案

How to use Model.query() with promises in SailsJS/Waterline?找到答案

day: function(req, res, next) {
var Promise = require('bluebird');
Lampo1.query("SELECT node FROM lampo1 WHERE id = ?", [ 15 ])
var dayQueryAsync = Promise.promisify(Lampo1.query);
dayQueryAsync("SELECT lampo FROM lampo1 WHERE id = ?", [ 15 ])
.then(function(lampo) {
console.log(lampo);
return res.json(lampo);
});

09-27 10:23