Querying User Data Response Format

Currently, I'm querying user data using the following code:
const res = await db
.select({
users,
emails
})
.from(users)
.leftJoin(workspaces, eq(workspaces.id, users.workspace_id))
.leftJoin(templates, eq(templates.workspace_id, users.workspace_id))
.leftJoin(
emails,
or(
eq(emails.user_email, users.email),
eq(emails.template_id, templates.id),
),
)
.where(
and(eq(users.id, user_id), eq(users.workspace_id, workspace_id)),
);
const res = await db
.select({
users,
emails
})
.from(users)
.leftJoin(workspaces, eq(workspaces.id, users.workspace_id))
.leftJoin(templates, eq(templates.workspace_id, users.workspace_id))
.leftJoin(
emails,
or(
eq(emails.user_email, users.email),
eq(emails.template_id, templates.id),
),
)
.where(
and(eq(users.id, user_id), eq(users.workspace_id, workspace_id)),
);

However, I want the response to be in the format like this:
{
user: {...},
emails: [{}, {}, ...]
}
{
user: {...},
emails: [{}, {}, ...]
}
Please suggest if anyone knows how I can achieve this.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server