我遇到了几个 sql server 错误,尝试使用羽毛 js 和 sequelize 开始使用简单的 rest api。我正在使用 SQL Server 2012 (express) 版本。
首先我的代码:
const { db } = require('../database');
const Sequelize = require('sequelize');
const service = require('feathers-sequelize');
const app = require('../app');
const Model = db.define('workorder', {
id: { type: Sequelize.INTEGER, primaryKey: true },
created_by: Sequelize.STRING,
modified_by: Sequelize.STRING,
status_name: Sequelize.STRING,
date_completed: Sequelize.DATE,
category: Sequelize.STRING,
location: Sequelize.STRING,
details: Sequelize.TEXT,
crew_name: Sequelize.STRING,
assigned_to: Sequelize.STRING,
}, {
schema: 'dbo',
freezeTableName: true,
createdAt: 'date_created',
updatedAt: 'date_modified',
});
app.use('/api/workorders', service({
Model,
id: 'id',
paginate: {
default: 10,
max: 100,
},
}));
当我点击 api 端点/api/workorders
时,它会出错:
SequelizeDatabaseError:FETCH 语句中选项 NEXT 的使用无效。
我看到生成的sql:
Executing (default): SELECT [id], [created_by], [modified_by], [status_name], [date_completed], [category], [location], [details], [crew_name], [assigned_to], [date_created], [date_modified] FROM [dbo].[workorder] AS [workorder] OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;
似乎 sql server 需要一些 ORDER BY 子句。所以我尝试向端点发送一个参数/api/workorders?$sort=id
这也会出错:
SequelizeDatabaseError:列名“1”无效。
生成的 SQL 如下所示:
Executing (default): SELECT [id], [created_by], [modified_by], [status_name], [date_completed], [category], [location], [details], [crew_name], [assigned_to], [date_created], [date_modified] FROM [dbo].[workorder] AS [workorder] ORDER BY [workorder].[0] DESC, [workorder].[1] DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;
这个错误更明显,没有第 1 列或第 0 列。
以前有人遇到过这些问题吗?