volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.66k stars 539 forks source link

sqlite3 driver doesn't seem to generate proper code for 'time' type #1136

Open gwd opened 2 years ago

gwd commented 2 years ago

If you're having a generation problem please answer these questions before submitting your issue. Thanks!

What version of SQLBoiler are you using (sqlboiler --version)?

SQLBoiler v4.11.0

What is your database and version (eg. Postgresql 10)

sqlite3 3.38.0

If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)

sqlboiler --wipe sqlite3

If this happened at runtime what code produced the issue? (if not applicable leave blank)

What is the output of the command above with the -d flag added to it? (Provided you are comfortable sharing this, it contains a blueprint of your schema)

Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)

drop table if exists viewlog;
create table viewlog (
    logno      integer primary key,
    userhash   text not null,
    passage    text not null,
    ts         time not null
);

Further information. What did you do, what did you expect?

The code generation succeeded, but the build failed:

$ go test -p 1 -v ./btdb/
btdb/viewlog.go:452:23: cannot use o.CreatedAt (variable of type string) as type driver.Valuer in argument to queries.MustTime:
        string does not implement driver.Valuer (missing Value method)
btdb/viewlog.go:453:23: cannot use &o.CreatedAt (value of type *string) as type sql.Scanner in argument to queries.SetScanner:
        *string does not implement sql.Scanner (missing Scan method)
btdb/viewlog.go:666:23: cannot use o.CreatedAt (variable of type string) as type driver.Valuer in argument to queries.MustTime:
        string does not implement driver.Valuer (missing Value method)
btdb/viewlog.go:667:23: cannot use &o.CreatedAt (value of type *string) as type sql.Scanner in argument to queries.SetScanner:
        *string does not implement sql.Scanner (missing Scan method)
FAIL    gitlab.com/[...]/tmp/btdb [build failed]
FAIL
stephenafamo commented 2 years ago

This is likely a semi-simple fix by adding the correct type in this switch statement here.

Not 100% sure when I'd get to it (pretty busy recently), but feel free to send a PR if you need it sooner. (PS: You can switch to your fork while waiting)