Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rishi-kulkarni opened this issue Dec 21, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@rishi-kulkarni
Copy link

rishi-kulkarni commented Dec 21, 2023

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 rishi-kulkarni added the bug Something isn't working label Dec 21, 2023
@go-jet
Copy link
Owner

go-jet commented Dec 24, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants