I'm trying to get all rows with specific ID in async/await
style using sequelize
. My code looks like:
UPDATED:
router.get('/', errorHandler(async (req, res, next) => {
let domainsDB = await Domain.findAll({
where: { accID: accID },
attributes: [`adID`, `domain`, `status`]
})
}
When I console.log(domainsDB)
I see this:
[
domains {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
__eagerlyLoadedAssociations: [],
isNewRecord: false },
domains {
...
...
...
]
The docs says it has to be an array in return. But console log shows this is an object. The data in this object in dataValues
is correct. There are my domains. But I expect to get an array to work with.
How to get an array in return with async/await?
Thank you for any help.
All you need is : raw : true
,
let domainsDB = await Domain.findAll({
where: { accID: accID },
attributes: [`adID`, `domain`, `status`],
raw : true // <--- HERE
})
By default model queries returns the sequelize
Object , to get the plain result we need to pass raw : true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With