Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何用bookshelfnodejs选择limitmysql_Javascript_Mysql_Node.js_Bookshelf.js - Fatal编程技术网

Javascript 如何用bookshelfnodejs选择limitmysql

Javascript 如何用bookshelfnodejs选择limitmysql,javascript,mysql,node.js,bookshelf.js,Javascript,Mysql,Node.js,Bookshelf.js,我正在使用NodeJS的bookshelf插件来执行mysql查询。但我不知道如何执行限制查询。那样 SELECT * from tableName LIMIT 2; 我的连接书架: Bookshelf.mysqlAuth = Bookshelf.initialize({ client: client, connection: { host : host, user : user, password : password,

我正在使用NodeJS的bookshelf插件来执行mysql查询。但我不知道如何执行限制查询。那样

SELECT * from tableName LIMIT 2;
我的连接书架:

Bookshelf.mysqlAuth = Bookshelf.initialize({
    client: client,
    connection: {
      host     : host,
      user     : user,
      password : password,
      database : database
    }
和数据方法:

bookshelf.Img = Bookshelf.Model.extend({
    tableName: 'image'
  });
您可以在调用连接时使用此选项:

  var qb = data.Img.query();
  qb.where('img_md5', '=', imgMD5save).update({img_size: fileLength, img_local_url: folder, img_type: fileType, img_downloaded: 1}).then(function(){});
我试过了

 qb.limit(5).then(function(){});
但它引发了一个错误

可能未处理的TypeError:无法调用未定义的方法“apply”

请提出解决方案。
谢谢大家!

查看您试图在
qb
模型上执行的操作后,您试图使用
LIMIT
子句运行
UPDATE
查询

  • LIMIT
    可与
    UPDATE
    一起使用,但只能与
    行计数一起使用
  • 参考这个
  • 不要在更新中使用
    LIMIT
    子句,我建议在
    update
    查询中加强
    WHERE
    子句
如果您只是想使用
LIMIT
子句运行
SELECT
查询,请查看下面我提供的代码片段:

var qb = data.Img.query();
  qb
    .select('*')
    .from('image')
    .where('img_md5', '=', imgMD5save)
    .limit(2)
    .then(function(result){
        return result;
    })
    .catch(function(error) {
        throw new error;
    });
根据以下说明,您可以这样写:

bookshelf.Img.query(function(qb) {
    qb.offset(30).limit(10);
})
.fetchAll()
.then(...);
这将返回从第30张图像开始的10张图像的集合