`Error [AssertionError]` when inserting `Buffer` in a `blob` column (SQLite)

I'm using SQLite / D1. I have a column hash: blob("hash", { mode: "buffer" }) Whenever I try to insert values like this: .values({ hash: Buffer.from(new Uint8Array([1, 2, 3])) } an error is thrown with cause: Error [AssertionError]: false == true I can insert Uint8Array or strings directly with no runtime errors, but with TypeScript errors. If i change the type (.$type<UInt8Array>) typing works, except when querying the returned value is of course not a Uint8Array but a Buffer behind the scenes. Am I missing something? Seems like blob columns do not work with Buffer for insertions/updates but returns Buffer for queries
2 Replies
praffn
praffnOP4mo ago
GitHub
🐛 BUG: D1 via miniflare doesn't accept Buffer type for blobs · ...
Which Cloudflare product(s) does this pertain to? D1, Miniflare What version(s) of the tool(s) are you using? 3.53.1 [Wrangler] What version of Node are you using? 20.10.0 What operating system and...
praffn
praffnOP4mo ago
I solved this for now by making an stupid custom type:
export const blob = customType<{
data: Buffer;
driverData: Buffer;
}>({
dataType() {
return "blob";
},
fromDriver(buffer) {
return buffer;
},
toDriver(buffer) {
return new Uint8Array(buffer) as Buffer;
},
});
export const blob = customType<{
data: Buffer;
driverData: Buffer;
}>({
dataType() {
return "blob";
},
fromDriver(buffer) {
return buffer;
},
toDriver(buffer) {
return new Uint8Array(buffer) as Buffer;
},
});
It works. This is not a Drizzle issue, but a Miniflare issue

Did you find this page helpful?