Hi,
I'm creating queries which fetch data directly from database (PostgeSQL).
I have 2 cases I want to ask for help with!
1- Getting all records from a Table (let's name this query getEmployee
),
ex 1: SELECT * FROM employee;
how can I convert the records into an array of objects (simple one without the need to use JS to covert it or something like this, maybe some retool tools or external libraries or at least less code to do it)
ex 2: SELECT * FROM employee WHERE id = 'uuid';
So how can I convert a single and many records into a single object or array of objects?
2- Same example above, but what if I have 2/3 relations with the same table how can I do it?
Ex 3: SELECT * FROM "employee" INNER JOIN "user" ON "employee"."userId" = "user"."id" INNER JOIN "user_image" ON "user"."imageId" = "user_image"."id" WHERE "employee"."id" = "uuid";
-- Please the SQL query I wrote might have some mistakes, but I guess it's clear to understand what I want to ask about!
So what I want to do and have in the second case: is when I want to use the fetched data from the query, I can easily read that data like the following:
- Employee Badge: getEmployee.data.badgeNumber
- Employee Name: getEmployee.data.user.name
- Employee Image: getEmployee.data.user.image.url