jet icon indicating copy to clipboard operation
jet copied to clipboard

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

Open rishi-kulkarni opened this issue 1 year ago • 2 comments
trafficstars

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):

  • OS: Linux
  • Database: SQLite
  • Database driver: mattn
  • Jet version v2.10.1

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.

rishi-kulkarni avatar Dec 21 '23 02:12 rishi-kulkarni

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.

go-jet avatar Dec 24 '23 15:12 go-jet