filter json field supabase drizzle

I have a case where I need to filter a json filed which contains an array of tags in the supabase database using drizzle but my syntax is wrong can anyone help me with this pls
No description
7 Replies
drcolonel
drcolonelOP8mo ago
any help on this?
Mykhailo
Mykhailo8mo ago
Hey @drcolonel! You can't use set-returning function in where clause that's why you face an error. I came up with this solution:
const sq = sql`(select 1 from json_array_elements_text(posts.categories) as elem where elem.value in ${categories})`;

const result = await db
.select()
.from(posts)
.where(categories.length > 0 ? exists(sq) : undefined); // add other conditions
const sq = sql`(select 1 from json_array_elements_text(posts.categories) as elem where elem.value in ${categories})`;

const result = await db
.select()
.from(posts)
.where(categories.length > 0 ? exists(sq) : undefined); // add other conditions
drcolonel
drcolonelOP8mo ago
Thank you so much @Mykhailo this did work perfectly.
Mykhailo
Mykhailo8mo ago
@drcolonel Super! Happy to hear it. By the way, could you please tell what are you building with Drizzle?
drcolonel
drcolonelOP8mo ago
@Mykhailo I'm building a multi vendor Ecommerce website
MithushanJ
MithushanJ7mo ago
Nice! Is this opensource project ?
Mykhailo
Mykhailo7mo ago
This is cool!
Want results from more Discord servers?
Add your server