How to store Uint8Array in postgresql

const users: pgTable("user", {
recovery_code: // what to use here?
})
const users: pgTable("user", {
recovery_code: // what to use here?
})
1 Reply
pandareaper
pandareaper5d ago
I don't know if drizzle supports that type natively, I implemented a custom type for this:
const binaryHash = customType<{ data: string; driverData: Buffer }>({
dataType() {
return 'bytea';
},
toDriver(hash: string): Buffer {
return Buffer.from(hash, 'hex');
},
fromDriver(hashBuffer: Buffer): string {
return hashBuffer.toString('hex');
},
});
const binaryHash = customType<{ data: string; driverData: Buffer }>({
dataType() {
return 'bytea';
},
toDriver(hash: string): Buffer {
return Buffer.from(hash, 'hex');
},
fromDriver(hashBuffer: Buffer): string {
return hashBuffer.toString('hex');
},
});

Did you find this page helpful?