4

How to loop data in RowDataPacket.

This problem happen because in addonis QueryBuild not return same value

as lucid models

If I use lucid models every work fine

const emp =  await EMP.all();
for(let i in emp.rows) {
      const data = emp.rows[i]

}

After I using querybuilder I do something like this

const emp =  await Database
                    .table('emp');



for(let i in emp.RowDataPacket) {
      console.log('s')
      const data = emp.RowDataPacket[i]
      const emp =  await emp_sell.query()
                                  .where('emp_id',data.id);
    }

It's not even display 's'

TryHard
  • 299
  • 4
  • 19

1 Answers1

4

When making this query await Database.table('emp');, you ended with an RowDataPacket objects, which is an object not iterable, as a workaround you could parse it to an array as:

JSON.parse(JSON.stringify(emp))

Further reading here.

guijob
  • 4,413
  • 3
  • 20
  • 39