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
I have a
![facePalm](https://cdn.discordapp.com/emojis/740380980115800086.png)
ShippingMethod
table with stores
field, which is array of Store
enum
I have this prisma query, filtering shipping methods which have Store.PUBLIC
in the stores
array field:
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! 🙏Solution:Jump to solution
That's currently ~the best way to do it unfortunately. Here's a more type-safe approach:
```ts
const shippingMethods2 = await this.dbService.db
.selectFrom('ShippingMethod')...
4 Replies
I think I got it working:
Solution
That's currently ~the best way to do it unfortunately. Here's a more type-safe approach:
Thank you ❤️
I'm currently adding the
any
function to the function module. With the next Kysely version you'll be able to say
fn.any
only accepts array columns and automatically checks the value type against the left operand.