DT
Drizzle Team•12mo ago
XandoR

Difference between query modes

Heyo everyone ! 👋 Is there anyway I can get same result than result1 query using result2 syntax with db.select() ?
const result1 = await db.query.notifications.findMany({
where: eq(notifications.guild_id, interaction.guildId),
with: {
group: true,
},
});

const result2 = await db
.select()
.from(notifications)
.limit(1)
.where(eq(notifications.guild_id, interaction.guildId))
.innerJoin(groups, eq(notifications.group_id, groups._id))
.execute();
const result1 = await db.query.notifications.findMany({
where: eq(notifications.guild_id, interaction.guildId),
with: {
group: true,
},
});

const result2 = await db
.select()
.from(notifications)
.limit(1)
.where(eq(notifications.guild_id, interaction.guildId))
.innerJoin(groups, eq(notifications.group_id, groups._id))
.execute();
Or should I keep using db.query if I want to retrieve notifications with group inside of it ?
1 Reply
Angelelz
Angelelz•12mo ago
You could do it, but you'll need to use json array aggregation sql functions You can take a look at the query that result1 produces to see what functions are used fair warning, it will be complicated if you're not familiar with sql
Want results from more Discord servers?
Add your server