从表的字段返回值



我尝试使用承诺返回表的字段值,但结果如下所示

router.get("/generateDemand", (req, res, next) => {
  const entreprise = req.user.entrepriseid;
  downloadFile(req, res, next, entreprise);
});
export const downloadFile = async (req, res, next, entreprise) => {
  const title1 = await Entreprise.findOne({
    attributes: ["entrepriseid", "titrefr"],
    where: { entrepriseid: entreprise }
  });
  console.log("title---------->", chalk.bgBlue(title1));
}

....

正在执行(默认(:从中选择"entrepriseid","titrefr" "entreprise"作为"entreprise",其中"entreprise"。企业" = "SDA";title----------> [object SequelizeInstance:entreprise] GET /附件/生成需求 200 71.459 毫秒 - 1638

通过调用 findOne 方法,您可以返回单个 Sequelize 模型实例,因此为了获取给定实例的指定字段(表记录的表示形式(,您应该使用 instance.get 方法,例如chalk.bgBlue(title1.get('fieldName'))

最新更新