Skip to content

Commit 2f85f3d

Browse files
committed
doc: add note for blob type conversion (closes #144)
1 parent a0cb59f commit 2f85f3d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

doc.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,21 @@ When retrieving rows, the types are mapped back to JavaScript types:
394394
| `TEXT` | `string` |
395395
| `TEXT` with JSON subtype | `object` (`JSON.parse()`) |
396396
| `BLOB` | `Uint8Array` |
397+
398+
Note: We only support `Uint8Array` for the `BLOB` type as V8 Fast API will
399+
optimize for it instead of other arrays like `Uint16Array`. And it is also to
400+
stay consistent: we only support passing `Uint8Array` and we consistently return
401+
`Uint8Array` when we return a `BLOB` to JS. It is easy to support passing all
402+
typed arrays with good performance, but then at the time we have to retreive
403+
again we don't know what the original typed array type was, as the only type
404+
into in the column is that it is a `BLOB`.
405+
406+
You can easily convert between other typed arrays and `Uint8Array` like this:
407+
408+
```ts
409+
const f32 = new Float32Array(1);
410+
const u8 = new Uint8Array(f32.buffer); // no copy, can pass this
411+
412+
const u8FromSqlite = new Uint8Array(4);
413+
const f32FromSqlite = new Float32Array(u8FromSqlite.buffer); // safely convert back when retrieved from sqlite, no copy
414+
```

0 commit comments

Comments
 (0)