kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
9.82k stars 250 forks source link

Type Error for BLOB columns when using D1 Databases #975

Closed kschniedergers closed 2 months ago

kschniedergers commented 2 months ago

When inserting/searching on a BLOB column when using D1, D1 expects an ArrayBuffer. However, when using an array buffer, I get a type error: Argument of type 'ArrayBuffer' is not assignable to parameter of type 'OperandValueExpressionOrList<DB, "Slp", "hash">'. Type 'ArrayBuffer' is missing the following properties from type 'Buffer': write, toJSON, equals, compare, and 99 more

example (the hash column is type Bytes):

const fileHash = await crypto.subtle.digest(
    "SHA-256",
     file.buffer,
);
const alreadyExists = await db
    .selectFrom('Slp')
    .select('id')
    .where('hash', '=', fileHash)
    // error is here    ^^^^^^^^
    .executeTakeFirst();

Here the error is on "fileHash" in the where clause. I can get the type error to go away by doing Buffer.from(fileHash), however d1 throws a runtime error when i do that.

Not a huge issue, its just a type error so a ts-ignore makes it go away just thought i should report it.

kschniedergers commented 2 months ago

ah whoops nevermind the d1 driver im using is not maintained somewhere else :3