tauri-apps / tauri-apps/plugins-workspace
[sql] Can't save binary data with `execute` (SQLite)
- Dominant language
- Rust
- Stars
- 1.8k
- Forks
- 602
- Avg merge
- 4d 14h
- Merged PRs (30d)
- 9
Description
First of all, thanks for your work on Tauri and essential plugins like this one!
I'm having trouble inserting `Uint8Array` data into `BLOB` columns in SQLite. Instead of being inserted as binary data, it's inserted as a stringified JSON object.
My main use case is a `uuid` column storing the 128-bit binary representation of a UUID.
```sql
CREATE TABLE node (
uuid BLOB PRIMARY KEY
-- ...
)
```
```typescript
const uuid = new Uint8Array(16) // this would be a generated 128-bit UUID
const result = await db.execute('INSERT INTO node (uuid) VALUES ($1)', [uuid])
```
What's inserted into `node.uuid`:
```js
'{"0":0,"1":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0}'
```
If I instead save the `ArrayBuffer` itself, I get an empty object:
```typescript
const uuid = new Uint8Array(16).buffer // its underlying ArrayBuffer
const result = await db.execute('INSERT INTO node (uuid) VALUES ($1)', [uuid])
```
```js
'{}'
```
Am I doing something wrong, or does the binary data simply not survive serialization when sent from JS to Rust?
If it's the latter, maybe [serde_binary](https://docs.rs/serde-binary/latest/serde_binary/) can be of help?
Contributor guide
Assessment
This issue has not been assessed yet.