sqlc
sqlc copied to clipboard
Emit pointer to a custom type in LEFT OUTER JOIN when using overrides
Version
1.22.0
What happened?
I have two tables like this
CREATE TABLE entity (
id SERIAL PRIMARY KEY,
);
CREATE TABLE req (
id SERIAL PRIMARY KEY,
TYPE TEXT NOT NULL,
operator TEXT NOT NULL,
entity_id INTEGER REFERENCES entity (id) ON DELETE CASCADE,
);
And I have the following sqlc override
emit_pointers_for_null_types: true
overrides:
- go_type:
import: "...packagepath.."
package: "models"
type: "ReqOperaor"
column: "req.operator"
Where ReqOperator is type ReqOperator = string (this is a go equivalent of an enum with validations and all that)
Now for a query like
SELECT *
FROM entity LEFT OUTER JOIN req ON req.entity_id = entity.id
The generated struct has Operator as ReqOperator instead of *ReqOperator. But Operator is nullable, so ideally, a pointer should be emitted here. Is there a way to make sqlc emit a pointer here?
Relevant log output
No response
Database schema
CREATE TABLE entity (
id SERIAL PRIMARY KEY,
);
CREATE TABLE req (
id SERIAL PRIMARY KEY,
TYPE TEXT NOT NULL,
operator TEXT NOT NULL,
entity_id INTEGER REFERENCES entity (id) ON DELETE CASCADE,
);
SQL queries
SELECT *
FROM entity LEFT OUTER JOIN req ON req.entity_id = entity.id
Configuration
version: "2"
sql:
- engine: "postgresql"
queries: "remote/db/sqlc"
schema: "remote/db/schema.sql"
gen:
go:
package: "pgdao"
out: "internal/dao/pg"
sql_package: "pgx/v5"
emit_prepared_queries: true
emit_pointers_for_null_types: true
emit_interface: true
emit_json_tags: true
emit_db_tags: true
overrides:
- go_type:
import: "...Packagepath..."
package: "models"
type: "ReqOperator"
column: "req.operator"
Playground URL
https://play.sqlc.dev/p/d4434940f766b1022428ca5f6663e80787b7498f326108fc0f2b74364656a6fc
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go