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
21.85k stars 496 forks source link

Feature Request: Support for binary data types #298

Open ksmithut opened 1 year ago

ksmithut commented 1 year ago

I have been loving diving into drizzle. I just started building out some basic tables I need for a side project, but I couldn't find how to store just a binary Blob. I'm specifically using postgres, but supporting binary types for all the SQL flavors that support binary types would be a great addition. It's possible drizzle supports it today and I just missed it in the documentation and type specs.

dankochetov commented 1 year ago

If you're talking about the bytea column type (which I believe represents the binary data in Postgres), It's not added yet. However, you can workaround that by creating a custom type, as described here - https://github.com/drizzle-team/drizzle-orm/blob/main/docs/custom-types.lite.md. Keep in mind that we're currently in a process of refactoring the internal types for the column builders, so the API might slightly change in the future.

For MySQL, we already have the binary column type, as well as blob for SQLite.

ksmithut commented 1 year ago

That's awesome! It's not a pressing need for me at the moment, but it's great to know that there's a workaround.

bradymwilliams commented 8 months ago

the workout seems to still want to truncate the table

jmaister commented 5 months ago

I am missing the BLOB, MEDIUMBLOB, LONGBLOB in MySQL. The BINARY type only works for lengths less than 255. The currenly supported TEXT, MEDIUMTEXT, LONGTEXT, try to store it as string, not binary.

image

jmaister commented 5 months ago

I made it work using a custom type:

const customLongBlob = customType<{ data: string }>({
    dataType() {
      return 'LONGBLOB';
    },
});
nick-kang commented 2 months ago

What we're doing. We're using the pg driver.

customType<{
  data: Buffer
  default: false
}>({
  dataType() {
    return 'bytea'
  },
})