drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
23.76k stars 590 forks source link

[FEATURE]: Support SET Type in MySQL with mysqlSet #1989

Open versecafe opened 7 months ago

versecafe commented 7 months ago

Describe what you want

Add support for the SET type in the same manor as mysqlEnum, should be created the same way, example schema:

export const blogPostsTable = mysqlTable("posts", {
  title: varchar("title", { length: 255 }).notNull().primaryKey(),
  content: text("content").notNull(),
  slug: varchar("slug", { length: 255 }).notNull(),
  tags: mysqlSet("tags", ["javascript", "typescript", "react", "vue", "nextjs", "nuxt", "angular"]).notNull()
});

MySQL Docs: https://dev.mysql.com/doc/refman/8.0/en/set.html

Query

const posts: Post[] = await db
    .select()
    .from(blogPostsTable)
    .where(findInSet(blogPostsTable.tags, ["react", "nextjs"]));
SELECT * FROM posts WHERE FIND_IN_SET('react,nextjs',tags);
tumblewader commented 1 month ago

Just to add to it, drizzle-kit introspect also fails if a table has a set column defined in it.