One of the examples for using DataLoader with Knex shows something this:
user: new DataLoader(ids => db.table('users')
.whereIn('id', ids).select()
.then(rows => ids.map(id => rows.find(x => x.id === id)))),
The map there is so that the keys in the array of keys always match up with the objects in the array of results, e.g. if object with id 2 is missing:
array of keys: [1,2,3]
array of results: [object1, undefined, object3]
If you left the map out, you'd get an unbalanced input/output (e.g. when querying for missing ids):
array of keys: [1,2,3]
array of results [object1, object3]
Is there any way to do the map
bit with pure SQL?