OP-Engineering/op-sqlite

Convert back to Uint8Array

Closed this issue · 2 comments

I just realized that you manually need to convert a document back to a Uint8Array.

const result = db.execute('SELECT content FROM BlobTable');

const finalUint8 = new Uint8Array(result.rows!._array[0].content);

Do you think there is a change this could be done automatically? The only idea I have is prefixing the data with info of the type, but not happy about it.

Why? This is how other implementations like sql.js also work

I don't think it is possible. JSI doesn't expose any way to interact with TypedArrays, only ArrayBuffers, so any type information is lost whenever the data is sent back & forth.

https://github.com/OP-Engineering/op-sqlite/blob/main/cpp/utils.cpp#L98
https://github.com/OP-Engineering/op-sqlite/blob/main/cpp/utils.cpp#L36

yeah makes sense, just a bit unfortunate - took mit a bit to find the issue https://github.com/serenity-kit/Serenity/pull/867/files