【发布时间】:2018-03-24 20:50:32
【问题描述】:
我正在使用 Sequelize、GraphQL 和 Typescript 来编写代码。 我有两个表 RecordInformation 和 OtherDescription。 RecordInformation 在 OtherDescription 表上有一个外键“OtherID”。
我的解析器文件中有以下两个代码。我可以使用 sequelize 中的级联选项删除记录。
但是,我想知道如何根据每个操作是否成功执行来更改此代码以仅返回 true 或 false 值。目前map操作的返回类型为Bluebird
interface IRecordInformation {
id: number;
RecordID: number;
LabelOptionID: number;
OtherID: number;
}
interface IListRecordInformation {
RecordInformationList: IRecordInformation[];
}
deleteRecordInformation(_: null, args: IListRecordInformation) {
const recordInformationList = args.RecordInformationList;
return recordInformationList.map((recordInfo) => OtherDescription.destroy({
where: { id: recordInfo.OtherID }
}));
},
【问题讨论】:
-
您可以使用
.every()。OtherDescription.destroy({ where: { id: recordInfo.OtherID } })是否返回Boolean? -
不,它返回一个数字,即影响的行数
-
布尔转数字的逻辑是什么?或者您想确定
.map()何时完成? -
我尝试添加此代码: deleteRecordInformation(_: null, args: IListRecordInformation) { const recordInformationList = args.RecordInformationList; return recordInformationList.map((recordInfo) => OtherDescription.destroy({ where: { id: recordInfo.OtherID } })).every(number => number > 0); },但它给出了 operator > 不能应用于 Bluebird
的错误 -
OtherDescription.destroy({ where: { id: recordInfo.OtherID } })是否返回Promise?
标签: javascript postgresql typescript sequelize.js graphql