drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

Feature Request: Support for binary data types

Open ksmithut opened this issue 1 year ago • 2 comments

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.

ksmithut avatar Mar 20 '23 12:03 ksmithut

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.

dankochetov avatar Mar 20 '23 13:03 dankochetov

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.

ksmithut avatar Mar 20 '23 21:03 ksmithut

the workout seems to still want to truncate the table

bradymwilliams avatar Nov 02 '23 21:11 bradymwilliams

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 avatar Jan 24 '24 23:01 jmaister

I made it work using a custom type:

const customLongBlob = customType<{ data: string }>({
    dataType() {
      return 'LONGBLOB';
    },
});

jmaister avatar Feb 01 '24 21:02 jmaister

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

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

nick-kang avatar Apr 21 '24 23:04 nick-kang