© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
5 replies
AlexNotTheLion

(Solved) Filter where json array contains

I have a json array of strings, an invite list of user ids (clerk is managing my users which is why its not a relation), im trying to get all results from the events table where the current users id is in the invite list or the host, using planetscale (mysql) and i cannot figure out the correct syntax this is what i have so far
const user = await currentUser();
  if (user === null) return [];

  const query = await db.query.events.findMany({
    where: or(eq(events.user_id, user.id), inArray(events.invited_users, [user.id]))
  });
const user = await currentUser();
  if (user === null) return [];

  const query = await db.query.events.findMany({
    where: or(eq(events.user_id, user.id), inArray(events.invited_users, [user.id]))
  });
and this is the schema for the events table
export const events = mysqlTable('event', {
    id: serial('id').primaryKey(),
    user_id: text('user_id').notNull(),
    start: timestamp('start', { mode: 'date' }).defaultNow().notNull(),
    end: timestamp('end', { mode: 'date' }).defaultNow().notNull(),
    title: varchar('title', { length: 50 }),
    description: varchar('description', { length: 500 }).default(""),
    invited_users: json("invited_users").$type<string[]>().default([]),
});
export const events = mysqlTable('event', {
    id: serial('id').primaryKey(),
    user_id: text('user_id').notNull(),
    start: timestamp('start', { mode: 'date' }).defaultNow().notNull(),
    end: timestamp('end', { mode: 'date' }).defaultNow().notNull(),
    title: varchar('title', { length: 50 }),
    description: varchar('description', { length: 500 }).default(""),
    invited_users: json("invited_users").$type<string[]>().default([]),
});
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Filter (Where)
Drizzle TeamDTDrizzle Team / help
3y ago
json_arrayagg(json_array ...
Drizzle TeamDTDrizzle Team / help
2y ago
Filter from array
Drizzle TeamDTDrizzle Team / help
2y ago
How to filter json column
Drizzle TeamDTDrizzle Team / help
2y ago