0

I am trying to use sqlboiler (using version 4.5.0) to generate my database-models in Golang.

I have a lot of tables with columns of type tinyint(1) or bit(1) which were mapped to booleans in my java spring code.

Now when I generate the sqlboiler code these columns are all mapped to strings instead of boolean or integer, so I get errors when it tries to insert "Y" or "N" as values.

I did find the undocumented property tinyint_as_int or tinyint_as_bool mentioned in a lot of threads, but setting these didn't change anything (I am using the mysql driver)

What can I do to properly map bit/tinyint columns into an integer or a boolean so sqlboiler does not try to insert a string there?

Update: Was my mistake, I changed the column from bit(1) to tinyint(1) in the wrong table. Would still be nice if mysqlboiler would support bit(1) but with tinyint it works

Juliette
  • 966
  • 16
  • 35
  • Did you read this issue discussion? Anything useful? https://github.com/volatiletech/sqlboiler/issues/80 – Hymns For Disco Apr 11 '21 at 07:36
  • @HymnsForDisco yes, they suggested the tinyint_as_int configuration that didn't work for me. Also according to the thread the issue was already fixed in v3 (and I think the poster has a slightly different problem because at least his struct is generated with an integer and not a string). But still ty :) – Juliette Apr 11 '21 at 07:39
  • This is strange. According to the change log, tinyint_as_bool should now be default behaviour. Also, looking at the logic for how it maps types, I don't see how it would select a string type for tintyint https://github.com/volatiletech/sqlboiler/blob/b799bec0cfe58dfff8042220442d20afcba4dd9e/drivers/sqlboiler-mysql/driver/mysql.go#L362 (notice that string is the default type for when the DB type doesn't match any case) – Hymns For Disco Apr 11 '21 at 07:54
  • @HymnsForDisco You're right. I made a mistake: When running the tests, a new database was generated and I accidentally made the changes in that database so that the generation still happened on my own database where the colums where bit(1) and not tinyint(1). It's a little unfortunate that sqlboiler can't handle bit(1) but when I change it to tinyint in the correct table, it works – Juliette Apr 11 '21 at 08:13

0 Answers0