简体   繁体   English

Sequelize 原始查询返回 TextRows 数组

[英]Sequelize Raw Query returns Array of TextRows

I am using sequelize in my project.我在我的项目中使用 sequelize。 I am using the following format to get the results.我正在使用以下格式来获取结果。 But each row in the result is returned as textRow.但是结果中的每一行都作为 textRow 返回。 Is it ok if I can directly access using the index or Do I need to convert textrow?如果我可以使用索引直接访问或者我需要转换 textrow 可以吗? Need your suggestions.需要你的建议。

const testQuery = await sequelizeConn.query(`select * from users where user_name = '${reqParams.userName}'`, {
         raw: true
      })
if(testQuery && testQuery.length > 0 && testQuery[0].length > 0){
}

You need to remove raw:true because already it's working like raw query and try promise instead of async/await.您需要删除 raw:true 因为它已经像原始查询一样工作并尝试使用 promise 而不是 async/await。

 sequelize.query(`select * from users where user_name = ${reqParams.userName}`, {model: users}) .then(function(result) { if(result && result.length > 0 && result[0].length > 0){ console.log(result); } }).catch(error=>{ console.log(error); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM