DT
Drizzle Team•2y ago
MAST

Has anyone done a custom `bytea` column type for postgres?

I'm trying to move our work project to drizzle and the first thing I encountered was the missing bytea column. There was an open issue for it in the github, so I was wondering if someone has already implemented bytea so that I can reuse it 😄
2 Replies
petja
petja•2y ago
export const bytea = customType<{ data: Buffer }>({
dataType() {
return "bytea";
},
fromDriver(value) {
if (typeof value === "object" && value instanceof Uint8Array) {
return Buffer.from(value);
}

throw new Error("Expected Uint8Array");
},
toDriver(buffer) {
return sql`decode(${buffer.toString("base64")}, 'base64')`;
},
});
export const bytea = customType<{ data: Buffer }>({
dataType() {
return "bytea";
},
fromDriver(value) {
if (typeof value === "object" && value instanceof Uint8Array) {
return Buffer.from(value);
}

throw new Error("Expected Uint8Array");
},
toDriver(buffer) {
return sql`decode(${buffer.toString("base64")}, 'base64')`;
},
});
Marc Bernard
Marc Bernard•2mo ago
do you have or know a repo that streams the binary to bytea (readable/writable)?
Want results from more Discord servers?
Add your server