Generated `Params` don't allow nullable values when `COALESCE` is used
Version
1.25.0
What happened?
I'm trying this
I expected the generated UpdateEnvParams to contain nullable types since:
- the schema contains
NOT NULLfields - the update SQL contains
COALESCE(?, <fieldname>)
Since the field is constrained as NOT NULL in the schema, then this allows updating a field when ? is not null, and leaving the field alone if ? is null.
Ideally, the user would pass some null fields and some not-null fields and I could pass those through to sqlc transparently via the generated UpdateEnvParams that would contain nullable types to pass to the SQL.
This code is hosted at https://github.com/bbkane/namedenv/
Relevant log output
No logs
Database schema
CREATE TABLE env (
"id" INTEGER PRIMARY KEY,
"name" TEXT NOT NULL,
"comment" TEXT,
"create_time" TEXT NOT NULL,
"update_time" TEXT NOT NULL,
UNIQUE(name)
) STRICT;
SQL queries
-- name: UpdateEnv :exec
UPDATE env SET
name = COALESCE(?, name),
comment = COALESCE(?, comment),
create_time = COALESCE(?, create_time),
update_time = COALESCE(?, update_time)
WHERE id = ?;
Configuration
version: "2"
sql:
- engine: "sqlite"
queries: "envsqlc.sql"
schema: "sqlite/connect/embedded_migrations"
gen:
go:
package: "sqlcgen"
out: "sqlite/sqlcgen"
Playground URL
No response
What operating system are you using?
macOS
What database engines are you using?
SQLite
What type of code are you generating?
Go
I'll be able to avoid this issue once https://github.com/sqlc-dev/sqlc/issues/2800 is implemented (I think can force a parameter to be null - still not sure how to override names in my SQLite queries).
Also see : https://github.com/sqlc-dev/sqlc/issues/2183
Duplicate of https://github.com/sqlc-dev/sqlc/issues/937