Migration from prisma to Drizzle

Hello, i'm migrating from prisma to drizzle in my nuxt 3 app. I have some issues migrating this file:
export default defineEventHandler(async (event) => {
const { favorite, category } = getQuery(event)
const prisma = usePrisma()

let whereClause: any

if (favorite === 'true') {
category === 'all'
? whereClause = {
favorite: true,
categories: { every: { category: {} } },
}
: whereClause = {
favorite: true,
categories: { some: { category: { slug: category } } },
}
}
else {
category === 'all'
? whereClause = {
categories: { every: { category: {} } },
}
: whereClause = {
categories: { some: { category: { slug: category } } },
}
}

return await prisma.talent.findMany({
where: whereClause,
orderBy: {
name: 'asc',
},
include: {
categories: {
include: {
category: true,
},
orderBy: {
category: {
name: 'asc',
},
},
},
},
})
})
export default defineEventHandler(async (event) => {
const { favorite, category } = getQuery(event)
const prisma = usePrisma()

let whereClause: any

if (favorite === 'true') {
category === 'all'
? whereClause = {
favorite: true,
categories: { every: { category: {} } },
}
: whereClause = {
favorite: true,
categories: { some: { category: { slug: category } } },
}
}
else {
category === 'all'
? whereClause = {
categories: { every: { category: {} } },
}
: whereClause = {
categories: { some: { category: { slug: category } } },
}
}

return await prisma.talent.findMany({
where: whereClause,
orderBy: {
name: 'asc',
},
include: {
categories: {
include: {
category: true,
},
orderBy: {
category: {
name: 'asc',
},
},
},
},
})
})
. Can you help me ? You can find my code here : https://github.com/arthurDanjou/website-v2/tree/drizzle and my schema here : https://github.com/ArthurDanjou/website-v2/blob/drizzle/server/database/schema.ts
GitHub
GitHub - ArthurDanjou/website-v2 at drizzle
Contribute to ArthurDanjou/website-v2 development by creating an account on GitHub.
GitHub
website-v2/server/database/schema.ts at drizzle · ArthurDanjou/webs...
Contribute to ArthurDanjou/website-v2 development by creating an account on GitHub.
2 Replies
G$Row
G$Row•8mo ago
Which part of it are you having trouble migrating?
Arthur Danjou 🧸
Arthur Danjou 🧸OP•8mo ago
I have to parameters : favorite and category. Favorite is a Boolean and category is a string (saved in db in the categories table). I want to fetch all the bookmarks of the selected category where the bookmarks are favorite or not (if favorite param is checked). And the category param can be ‘all’ so I want to fetch all the bookmarks favorite or not (depends again of the favorite param) I found the solution :
const talents = await useDB().query.talents
.findMany({
orderBy: [asc(tables.talents.id)],
with: {
talentCategories: {
with: {
category: true,
},
},
},
})

return talents.filter(talent =>
(category === 'all' || talent.talentCategories.some(cat => cat.category.slug === category))
&& (favorite === 'false' || talent.favorite),
)
const talents = await useDB().query.talents
.findMany({
orderBy: [asc(tables.talents.id)],
with: {
talentCategories: {
with: {
category: true,
},
},
},
})

return talents.filter(talent =>
(category === 'all' || talent.talentCategories.some(cat => cat.category.slug === category))
&& (favorite === 'false' || talent.favorite),
)
` SImplified with drizzle Better than prisma
Want results from more Discord servers?
Add your server