const enrichedUser = await client
.select({
user: usersTable,
integrations: sql<Integration[]>`json_agg(integrations.*)`,
websites: sql<Website[]>`json_agg(websites.*)`,
})
.from(usersTable)
.where(eq(usersTable.id, userId))
.leftJoin(integrationsTable, eq(integrationsTable.userId, usersTable.id))
.leftJoin(websitesTable, eq(websitesTable.userId, usersTable.id))
.orderBy(desc(websitesTable.createdAt))
.groupBy(usersTable.id, websitesTable.createdAt)
.execute()
.then((r) => r[0]);
const enrichedUser = await client
.select({
user: usersTable,
integrations: sql<Integration[]>`json_agg(integrations.*)`,
websites: sql<Website[]>`json_agg(websites.*)`,
})
.from(usersTable)
.where(eq(usersTable.id, userId))
.leftJoin(integrationsTable, eq(integrationsTable.userId, usersTable.id))
.leftJoin(websitesTable, eq(websitesTable.userId, usersTable.id))
.orderBy(desc(websitesTable.createdAt))
.groupBy(usersTable.id, websitesTable.createdAt)
.execute()
.then((r) => r[0]);