Eternal Mori
Eternal Mori
Explore posts from servers
DTDrizzle Team
Created by Eternal Mori on 3/16/2024 in #help
drizzle-kit push error: Multiple primary key defined
No description
3 replies
DTDrizzle Team
Created by Eternal Mori on 10/17/2023 in #help
How to mimic the prisma cursor option for use with useInfiniteQuery
How to mimic the cursor option in drizzle with MySQL? This is the Prisma documentation: https://www.prisma.io/docs/concepts/components/prisma-client/pagination#cursor-based-pagination
4 replies
DTDrizzle Team
Created by Eternal Mori on 7/12/2023 in #help
How can I filter on a joined table field (nested value) with the relational query syntax?
☝🏻
1 replies
DTDrizzle Team
Created by Eternal Mori on 7/12/2023 in #help
How to implement a where clause on a joined table with the new relation builder?
This was my original query, the big problem is that it returns as many rows as there are messages instead of one entry with multiple messages. As you can see, I have a where clause where the entry is filtered with it's id, and a organization id that is part of another joined table named channel.
const tickets = await db
.select({
id: s.tickets.id,
status: s.tickets.status,
channel: {
id: s.channels.id,
type: s.channels.type,
name: s.channels.name,
},
contact: {
id: s.contacts.id,
name: s.contacts.name,
email: s.contacts.email,
},
messages: {
id: s.messages.id,
subject: s.messages.subject,
text: s.messages.text,
html: s.messages.html,
createdAt: s.messages.createdAt,
},
})
.from(s.tickets)
.innerJoin(s.contacts, eq(s.tickets.contactId, s.contacts.id))
.innerJoin(s.channels, eq(s.tickets.channelId, s.channels.id))
.leftJoin(s.messages, eq(s.tickets.id, s.messages.ticketId))
.where(
and(
eq(s.tickets.id, params.id),
eq(s.channels.organizationId, organizationId)
)
);

const ticket = tickets[0];
const tickets = await db
.select({
id: s.tickets.id,
status: s.tickets.status,
channel: {
id: s.channels.id,
type: s.channels.type,
name: s.channels.name,
},
contact: {
id: s.contacts.id,
name: s.contacts.name,
email: s.contacts.email,
},
messages: {
id: s.messages.id,
subject: s.messages.subject,
text: s.messages.text,
html: s.messages.html,
createdAt: s.messages.createdAt,
},
})
.from(s.tickets)
.innerJoin(s.contacts, eq(s.tickets.contactId, s.contacts.id))
.innerJoin(s.channels, eq(s.tickets.channelId, s.channels.id))
.leftJoin(s.messages, eq(s.tickets.id, s.messages.ticketId))
.where(
and(
eq(s.tickets.id, params.id),
eq(s.channels.organizationId, organizationId)
)
);

const ticket = tickets[0];
4 replies
DTDrizzle Team
Created by Eternal Mori on 7/3/2023 in #help
Broken typescript in select
3 replies
DTDrizzle Team
Created by Eternal Mori on 6/29/2023 in #help
Typescript error with custom column type
2 replies