zombiezen / go-sqlite

Low-level Go interface to SQLite 3
https://pkg.go.dev/zombiezen.com/go/sqlite
ISC License
741 stars 18 forks source link

Expose valid int64 types #39

Closed delaneyj closed 2 years ago

delaneyj commented 2 years ago

Get/SetInt64 is great but per the SQLite docs...

INTEGER. The value is a signed integer, stored in 0, 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.

This would be we should be able to use

byte
int8
int16
int32
int64
uint8
uint16
uint32
uint64

By using the proper size we eliminate extra casting and memory allocations

zombiezen commented 2 years ago

I'm not sure what you're asking for here. The underlying C API doesn't expose anything beyond 64-bit signed integers (there are int versions for easy usage in C, but basically equivalent to what this wrapper does): https://www.sqlite.org/c3ref/column_blob.html

The doc you're citing describes the on-disk format, which is selected automatically based on the value itself. The casting may be an inconvenience, but IMO makes it explicit what is occurring, especially that uint64 isn't supported. AFAIK, there are no extra allocations, just sign extensions which are cheap.

delaneyj commented 2 years ago

Ah, my fault... I thought the C side did expose those, not just the on disk model. Figured instead of casting unnecessarily it could just pass through. Int64 to UInt64 is cheap. Just didn't want int64->u8 casts when its wasn't needed.