knex.js在服务器端代码中验证查询结果

mwngjboj  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(408)

我有一个函数,应该检查我的mysql数据库中是否已经存在一个车牌,但是在返回时,结果是:result:[object]。如何实际获得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、 这不会出错,它会一直执行。

beq87vna

beq87vna1#

尝试

knex.select('plate').from('licensePlates').where('plate', licensePlate)

实际上使用count查询会更好

相关问题