我正在尝试使用“准备好的语句示例”(http://sailsjs.org/documentation/reference/waterline-orm/models/query),但我只得到“错误: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);
});
},
所以我尝试进行查询并添加值作为参数,但似乎根本不会生成查询。上述链接的基本示例查询有效。
答案 0 :(得分:0)
从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);
});