Suleyman
Suleyman
Explore posts from servers
DTDrizzle Team
Created by Suleyman on 12/16/2023 in #help
How to add external data in select
I want to add external data in select, but it only works with sql.
this.drizzle.get({
from: users,
select: {
id: users.id,
username: users.username,
name: users.name,
surname: users.surname,
email: users.email,
job: users.job,
phone: users.phone,
avatar: users.avatar,
last_seen: users.lastSeen,
organization_id: users.organizationId,
otp_enabled: users.otpEnabled,
is_webauth: users.isWebauth,
},
page: query.page,
perPage: query.per_page,
})
.where(GetUsersWhere(query))
.orderBy(desc(users.lastSeen))
.execute()
// My solution
.then(async (users) => {
return await Promise.all(
users.map(
async (user: { organization_id: number }) => {
const jobs = await this.orgService.nestedUserJobs(user.organization_id);
return {
...user,
jobs
}
}))
});
this.drizzle.get({
from: users,
select: {
id: users.id,
username: users.username,
name: users.name,
surname: users.surname,
email: users.email,
job: users.job,
phone: users.phone,
avatar: users.avatar,
last_seen: users.lastSeen,
organization_id: users.organizationId,
otp_enabled: users.otpEnabled,
is_webauth: users.isWebauth,
},
page: query.page,
perPage: query.per_page,
})
.where(GetUsersWhere(query))
.orderBy(desc(users.lastSeen))
.execute()
// My solution
.then(async (users) => {
return await Promise.all(
users.map(
async (user: { organization_id: number }) => {
const jobs = await this.orgService.nestedUserJobs(user.organization_id);
return {
...user,
jobs
}
}))
});
is that way has to do like
{
select: {
jobs: (user) => await this.orgService.nestedUserJobs(user.organization_id)
}
}
{
select: {
jobs: (user) => await this.orgService.nestedUserJobs(user.organization_id)
}
}
18 replies
DTDrizzle Team
Created by Suleyman on 12/14/2023 in #help
Nest.js mysql connection type like PostgreSQL
No description
4 replies