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 😄
1 Reply
petja
petja•17mo 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')`;
},
});
Want results from more Discord servers?
Add your server