volatiletech / sqlboiler

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

Compilation Errors with TIMESTAMP Columns in sqlite3 Driver #1363

Closed hirasawayuki closed 3 months ago

hirasawayuki commented 4 months 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)?

v4.16.2

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

v3.45.1

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

$ sqlboiler 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)

CREATE TABLE IF NOT EXISTS users(\
    id TEXT PRIMARY KEY NOT NULL,\
    name TEXT NOT NULL,\
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP\
);

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

When generating code with sqlboiler for tables containing TIMESTAMP columns using the sqlite3 driver, the generated field types are string, which leads to compilation errors due to the absence of implementations for driver.Valuer and sql.Scanner.

スクリーンショット 2024-03-07 22 29 56

Expect For consistency with DATETIME columns, it would be beneficial if TIMESTAMP columns were automatically mapped to time.Time in the generated Go code. This change would avoid the compilation errors currently encountered.

Proposed Solution I propose adjusting the sqlboiler code generation process to treat TIMESTAMP columns similarly to DATETIME columns by mapping them to time.Time type instead of string. This would align with Go's standard practices for handling timestamps and date/time values, enhancing the usability and reliability of the generated code.