You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got a SQLite table with a TEXT data type called create_time . I update create_time with the following update query:
-- See https://docs.sqlc.dev/en/latest/howto/named_parameters.html#nullable-parameters-- name: EnvUpdate :execUPDATE env SET
create_time = COALESCE(sqlc.narg('create_time'), create_time)
WHERE id =sqlc.arg('id');
This works fine and generates an update query parameter with a string pointer as I expect when using sqlc.narg:
However, if I create the type type SQLiteTime string and set create_time to use this type in sqlc.yaml (which I would like to do so I can attach methods to the type), the generated update code does NOT use a pointer as I expect:
Not having it be a pointer means I can't assign nil to it, which breaks my COALESCE SQL update query.
As a full reproducible demo of this bug, I've made https://github.com/bbkane/sqlc-override-nullable . It has a using-text package that demos the correct codegen, and a using-overrides that demos the incorrect codegen.
Some more context about WHY I'd like to be able to to this:
I'm writing an environment variable manager CLI that needs to store times. Instead of the "sqlc-native" format as a stringified time.Time, I want to store times in the "sqlite-native" format as a text column so I can run datetime queries on the columns.
Finally, thank you so much for writing sqlc! I've started GitHub sponsoring you because this tool removes a lot of the drudgery of working with SQL from Go, and I really appreciate that.
Relevant log output
No response
Database schema
CREATETABLEenv (
id INTEGERPRIMARY KEY,
create_time TEXTNOT NULL
) STRICT;
SQL queries
-- See https://docs.sqlc.dev/en/latest/howto/named_parameters.html#nullable-parameters-- name: EnvUpdate :execUPDATE env SET
create_time = COALESCE(sqlc.narg('create_time'), create_time)
WHERE id =sqlc.arg('id');
Configuration
sql:
- engine: sqlitegen:
go:
emit_pointers_for_null_types: trueout: sqlcgenpackage: sqlcgenoverrides:
- column: "env.create_time"go_type: "go.bbkane.com/sqlc-override-nullable/using-override/sqlite.SQLiteTime"queries: queriesschema: migrations# yq wants to double quote "2", but yamllint wants it single-quoted# yamllint disable-line rule:quoted-stringsversion: "2"
Playground URL
No response
What operating system are you using?
Linux, macOS
What database engines are you using?
SQLite
What type of code are you generating?
Go
The text was updated successfully, but these errors were encountered:
Version
1.26.0
What happened?
I've got a SQLite table with a TEXT data type called create_time . I update create_time with the following update query:
This works fine and generates an update query parameter with a string pointer as I expect when using
sqlc.narg
:However, if I create the type
type SQLiteTime string
and set create_time to use this type in sqlc.yaml (which I would like to do so I can attach methods to the type), the generated update code does NOT use a pointer as I expect:I would expect it to look like:
Not having it be a pointer means I can't assign
nil
to it, which breaks myCOALESCE
SQL update query.As a full reproducible demo of this bug, I've made https://github.com/bbkane/sqlc-override-nullable . It has a
using-text
package that demos the correct codegen, and ausing-overrides
that demos the incorrect codegen.Some more context about WHY I'd like to be able to to this:
I'm writing an environment variable manager CLI that needs to store times. Instead of the "sqlc-native" format as a stringified
time.Time
, I want to store times in the "sqlite-native" format as a text column so I can run datetime queries on the columns.Finally, thank you so much for writing sqlc! I've started GitHub sponsoring you because this tool removes a lot of the drudgery of working with SQL from Go, and I really appreciate that.
Relevant log output
No response
Database schema
SQL queries
Configuration
Playground URL
No response
What operating system are you using?
Linux, macOS
What database engines are you using?
SQLite
What type of code are you generating?
Go
The text was updated successfully, but these errors were encountered: