-
Notifications
You must be signed in to change notification settings - Fork 1k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Version
1.30.0
What happened?
I’m trying to map a Postgres array of integers (smallint[]) to a slice of a protobuf enum in Go using sqlc overrides, but I can’t get it to work.
sqlc fails to parse the type because it does not allow [] in the type field. It seems there is no way to override a Postgres array column to a slice of a custom Go type (like an enum). It would be great if sqlc could support mapping Postgres array types to Go slices of custom types (enums, structs, etc.) directly.
I expected sqlc would generate (at the back of a type: "[]WorkArrangement"):
type GetHuntsRow struct {
WorkArrangements []commonv1.WorkArrangement `json:"work_arrangements"`
}Relevant common.proto enum definition:
enum WorkArrangement {
REMOTE = 1;
HYBRID = 2;
ON_LOCATION = 3;
}Relevant log output
error generating code: expected 'IDENT', found '['Database schema
CREATE TABLE hunts (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
-- common.proto WorkArrangement: 1=remote; 2=hybrid; 3=onlocation
work_arrangements smallint[] NOT NULL DEFAULT '{}'
);SQL queries
Configuration
version: "2"
plugins:
- name: "golang"
wasm:
url: "https://downloads.sqlc.dev/plugin/sqlc-gen-go_1.5.0.wasm"
sha256: "4ca52949f4dc04b55188439f5de0ae20af2a71e3534b87907f2a7f466bda59ec"
sql:
- schema: "migrations"
engine: "postgresql"
codegen:
- plugin: "golang"
out: "generated"
options:
package: "sqlc"
sql_package: "pgx/v5"
emit_json_tags: true
emit_pointers_for_null_types: true
overrides:
- column: "hunts.work_arrangements"
go_type:
import: "github.com/user/company/go-packages/connectrpc/generated/common/v1"
package: "commonv1"
type: "WorkArrangement"Playground URL
No response
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working