Tedious or Sequelize uses the wrong syntax for `findOne()`

前端 未结 6 1119
青春惊慌失措
青春惊慌失措 2021-02-06 08:51

I am using Sequelize with Tedious to access SQL Server 2008.

When I do a sequelizeModel.findOne() I get this exception -

Unhandled

6条回答
  •  忘掉有多难
    2021-02-06 09:47

    This is an issue in Sequelize -- it uses the OFFSET FETCH syntax, which is only supported in SQL Server 2012 and newer.

    I submitted this as an issue on GitHub: https://github.com/sequelize/sequelize/issues/4404

    The issue also affects the findById method. A workaround for that method is to use findAll with a where to specify the ID, and just only use the first element from the returned array:

    Thing.findAll({
      where: {id: id}
    }).then( function(things) {
      if (things.length == 0) {
        // handle error
      }
      doSomething(things[0])
    }).catch( function(err) {
      // handle error
    });
    

提交回复
热议问题