go-jet / jet

Type safe SQL builder with code generation and automatic query result data mapping
Apache License 2.0
2.52k stars 118 forks source link

SQLite INTEGER and REAL types are generated as int32 and float32 despite being stored as 64-bit #302

Open rishi-kulkarni opened 9 months ago

rishi-kulkarni commented 9 months ago

Describe the bug Per this page about SQLite's data types, INTEGER and REAL columns are loaded into memory as 64-bit ints and floats, respectively. However, jet generates these as 32-bit values, losing some precision:

Environment (please complete the following information):

Code snippet For example, if I have this schema:

sqlite> pragma table_info(shift_recommendations);
0|user_id|INTEGER|1||1
1|ranking|INTEGER|1||2
2|shift_id|INTEGER|1||0
12|date_updated|DATETIME|1||0

user_id, etc should be 64-bit ints, but Jet makes the following model:

type ShiftRecommendations struct {
    UserID          int32 `sql:"primary_key"`
    Ranking         int32 `sql:"primary_key"`
    ShiftID         int32
    DateUpdated     time.Time
}

Expected behavior By default, INTEGER and REAL models should be 64-bit objects in Go.

I am aware that setting the column types in SQLite to BIGINT and DOUBLE generates 64-bit Go types, but these aren't actually real dtypes in SQLite and would therefore prevent using STRICT tables.

go-jet commented 9 months ago

Yeah, I agree. The fix would probably break some builds, but it is better to be safe. In the meantime, you can use generator customization to change model types.