Hi, I recently tried out SQL with knex and have a question with joined data:I have a one-to-many relationship between user and tasks table:Now I run this select query:Select users.name,tasks.id, tasks.name from users left join tasks where users.id = tasks.user_idthe result is the followingJohn, 1123, Task 1John, 1124, Task 2John, 1125, Task 3I know that this is the standard behaviour of SQL. I am wondering how you prettify the sql results afterwards in NodeJs to be more object based. like MongoDB results, or how Eloquent results in Laravel(php) looks like..So my desired result of above query would be:name: John,tasks: [{id:1123,name: 'Task 1'},{id:1124,name: 'Task 2'},{id:1125,name: 'Task 3'}]How you guys do this in NodeJs with SQL?Thx!
Submitted August 19, 2019 at 12:19PM by style-112
No comments:
Post a Comment