wod
wod
Explore posts from servers
KKysely
Created by wod on 7/22/2023 in #help
where array_field has enum value
Hello there 👋 Today I'm experimenting with kysely, coming from prisma. I got stuck on rewriting the first query facePalm I have a ShippingMethod table with stores field, which is array of Store enum
export const Store = {
PUBLIC: 'PUBLIC',
RETAIL: 'RETAIL',
WHOLESALE: 'WHOLESALE',
} as const;
export const Store = {
PUBLIC: 'PUBLIC',
RETAIL: 'RETAIL',
WHOLESALE: 'WHOLESALE',
} as const;
I have this prisma query, filtering shipping methods which have Store.PUBLIC in the stores array field:
const shippingMethods = await this.prismaService.shippingMethod.findMany({
where: {
stores: { has: Store.PUBLIC },
minAmount: 0,
minWeight: 0,
},
});
const shippingMethods = await this.prismaService.shippingMethod.findMany({
where: {
stores: { has: Store.PUBLIC },
minAmount: 0,
minWeight: 0,
},
});
Could anyone please guide me on how to achieve the same with kysely and postgresql dialect? I've found this can be achieved in postgresql using ANY(stores), but I wasn't able to build the query (https://commandprompt.com/education/how-to-check-if-postgresql-array-contains-a-value/). Thanks in advance! 🙏
8 replies