drizzle-orm
drizzle-orm copied to clipboard
Feature Request: Support for binary data types
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.
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.
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.
the workout seems to still want to truncate the table
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.
I made it work using a custom type:
const customLongBlob = customType<{ data: string }>({
dataType() {
return 'LONGBLOB';
},
});
What we're doing. We're using the pg
driver.
customType<{
data: Buffer
default: false
}>({
dataType() {
return 'bytea'
},
})