Knex.js 在服务器端代码中验证查询结果
Knex.js verifying query results in server side code
我有一个功能应该检查我的 MySQL 数据库中是否已经存在车牌,但在当时的承诺中 - return 结果如下:
结果:[对象对象]。您实际上如何获得此 knex 查询的响应并对其进行解析以检查是否存在车牌?
var licensePlateExists = function(licensePlate){
knex.select('plate').from('licensePlates').where({'plate': licensePlate}).limit(1).then(function(result){
console.log("Result: " + result);
if(!result){
return true;
}
return false;
}).catch(function(error) {
console.error(error);
});
}
我想我可能有一个与查询本身相关的错误,但我在 MySQL CLI 中测试了原始查询字符串,它按预期输出了行。也许在 knex 查询生成器中排序很重要?
P.S。这个没有报错,一直执行到这里。
试试
knex.select('plate').from('licensePlates').where('plate', licensePlate)
实际上使用计数查询会更好
我有一个功能应该检查我的 MySQL 数据库中是否已经存在车牌,但在当时的承诺中 - return 结果如下: 结果:[对象对象]。您实际上如何获得此 knex 查询的响应并对其进行解析以检查是否存在车牌?
var licensePlateExists = function(licensePlate){
knex.select('plate').from('licensePlates').where({'plate': licensePlate}).limit(1).then(function(result){
console.log("Result: " + result);
if(!result){
return true;
}
return false;
}).catch(function(error) {
console.error(error);
});
}
我想我可能有一个与查询本身相关的错误,但我在 MySQL CLI 中测试了原始查询字符串,它按预期输出了行。也许在 knex 查询生成器中排序很重要?
P.S。这个没有报错,一直执行到这里。
试试
knex.select('plate').from('licensePlates').where('plate', licensePlate)
实际上使用计数查询会更好