D1 Blobs as ArrayBuffer?

Hey folks, I'm trying to store ArrayBuffers in D1 as Blobs. This Cloudflare page seems to indicate that D1 will automatically do the marshalling of blobs <> ArrayBuffers https://developers.cloudflare.com/d1/build-with-d1/d1-client-api/#type-conversion But I am just getting plain number arrays back unless I use a custom type:
export const arrayBuffer = (name: string) =>
customType<{ data: ArrayBuffer; driverData: number[] }>({
dataType: () => "blob",
toDriver: (value) => [...new Uint8Array(value)],
fromDriver: (value) => new Uint8Array([...value]).buffer,
})(name)
export const arrayBuffer = (name: string) =>
customType<{ data: ArrayBuffer; driverData: number[] }>({
dataType: () => "blob",
toDriver: (value) => [...new Uint8Array(value)],
fromDriver: (value) => new Uint8Array([...value]).buffer,
})(name)
It feels like doing this operation on every query will be slow, so I'm wondering if there's another way to get an ArrayBuffer out of this whole thing?
Cloudflare Docs
Query D1 | Cloudflare D1 docs
D1 is compatible with most SQLite’s SQL convention since it leverages SQLite’s query engine. D1 client API allows you to interact with a D1 database from within a Worker.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server