user846445
user846445

Reputation: 231

Sequelize Raw Query returns Array of TextRows

I am using sequelize in my project. I am using the following format to get the results. But each row in the result is returned as textRow. Is it ok if I can directly access using the index or Do I need to convert 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){
}

Upvotes: 0

Views: 736

Answers (1)

Aum Trivedi
Aum Trivedi

Reputation: 147

You need to remove raw:true because already it's working like raw query and try promise instead of 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);
});
    
    

Upvotes: 1

Related Questions