trevyn / turbosql

An easy local data persistence layer for Rust, backed by SQLite.
208 stars 8 forks source link

`u64`: Some thoughts. #3

Open trevyn opened 3 years ago

trevyn commented 3 years ago

This is the error message if you try to Turbosql a u64:

SQLite cannot natively store unsigned 64-bit integers, so Turbosql does not support u64 fields. Use i64, u32, f64, or a string or binary format instead.

rusqlite provides an interesting feature i128_blob:

i128_blob allows storing values of type i128 type in SQLite databases. Internally, the data is stored as a 16 byte big-endian blob, with the most significant bit flipped, which allows ordering and comparison between different blobs storing i128s to work as expected.

So it would be possible to support i128_blob in Turbosql too, and support u64 mapped in this same way to a SQLite BLOB. This would definitely have to be gated behind an opt-in feature (u64_i128_as_blob?) to make clear that these two primitive numeric datatypes in Rust will behave differently than the others from SQLite's perspective. (BLOB serial type code vs an integer serial type code: https://sqlite.org/fileformat.html#record_format ) This would also affect any external software that might want to read the data from the .sqlite file.