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
24.64k stars 650 forks source link

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

Open versecafe opened 8 months ago

versecafe commented 8 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 2 months ago

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