Chaimba
DTDrizzle Team
•Created by Chaimba on 2/6/2024 in #help
Help with a request
Hey, guys, I'm new here. Here's my schema.
export const Anime = pgTable('Anime', {
id: serial('id').primaryKey(),
name: text('name').notNull().unique(),
img: text('img').notNull(),
imgHeader: text('imgHeader').notNull(),
describe: text('describe').notNull(),
genres: text('genres').array().notNull(),
author: text('author').notNull(),
country: text('country').notNull(),
published: integer('published'),
averageRating: doublePrecision('averageRating').default(0),
ratingCount: integer('ratingCount').default(0),
status: text('status').notNull(),
popularity: integer('popularity').default(0),
})
export const Users = pgTable('User', {
id: serial('id').primaryKey().notNull(),
name: text('name').notNull(),
email: text('email').notNull(),
image: text('image').notNull(),
favorite: text('favorite').array(),
createdAt: timestamp('createdAt').defaultNow().notNull(),
})
Here's a function with prisma that I can't rewrite myself to drizzle
async getUserFavoriteAnime(email: string) {
const user = await getUserFavorite(email);
if (!user?.favorite || user?.favorite.length === 0) {
return [];
}
return prisma.anime.findMany({
where: { name: { in: user?.favorite } },
});
}
In user.favorite I have an array of names and I want to find all the Anime that are in that array of names.
4 replies