Skip to content

Override timestpamtz does not work for me. #3751

@idefixcert

Description

@idefixcert

Version

1.27.0

What happened?

I have:

        emit_result_struct_pointers: true
        emit_params_struct_pointers: true
        emit_pointers_for_null_types: true
        overrides:
          - db_type: "timestamptz"
            nullable: false
            go_type:
              type: "time.Time"
              pointer: false
          - db_type: "timestamptz"
            nullable: true
            go_type:
              type: "time.Time"
              pointer: true

also I have

create table if not exists portal.purchase_order
(
    id                 bigint       not null
        constraint purchase_order_pk
            primary key,
    uuid               char(36)  not null
        constraint purchase_order_uk
            unique,
    parent_id          bigint
        constraint purchase_order_purchase_order_id_fk
            references portal.purchase_order,
    organization_id          bigint not null 
        constraint purchase_order_organization_id_fk
            references portal.organization,
    name               varchar(255) NOT NULL,
    note               text,
    license_server_url text         NOT NULL,
    tsnotbefore         timestamptz  NOT NULL DEFAULT CURRENT_TIMESTAMP,
    tsnotafter             timestamptz NOT NULL,
    tscreated         timestamptz  NOT NULL DEFAULT CURRENT_TIMESTAMP,
    tsmodified         timestamptz  NOT NULL DEFAULT CURRENT_TIMESTAMP,
    tsapproved        timestamptz,
    tsrejected        timestamptz,
    tsexpack        timestamptz,
    license_days_valid  int NOT NULL
);

and

-- name: PurchaseOrderUpdate :exec
UPDATE portal.purchase_order
SET
    name = @name,
    note = @note,
    parent_id = @parent_id,
    license_server_url = @license_server_url,
    tsnotbefore = @tsnotbefore::timestamptz,
    tsnotafter = @tsnotafter::timestamptz,
    license_days_valid = @license_days_valid,
    tsmodified=CURRENT_TIMESTAMP,
    tsapproved = @tsapproved::timestamptz
WHERE uuid = @uuid
;

I would assume that tsapproved will become a pointer
but I get:

type PurchaseOrderUpdateParams struct {
	Name             string
	Note             *string
	ParentID         *int64
	LicenseServerURL string
	Tsnotbefore      time.Time
	Tsnotafter       time.Time
	LicenseDaysValid int32
	Tsapproved       time.Time
	UUID             string
}

Relevant log output

No response

Database schema

create table if not exists portal.purchase_order
(
    id                 bigint       not null
        constraint purchase_order_pk
            primary key,
    uuid               char(36)  not null
        constraint purchase_order_uk
            unique,
    parent_id          bigint
        constraint purchase_order_purchase_order_id_fk
            references portal.purchase_order,
    organization_id          bigint not null 
        constraint purchase_order_organization_id_fk
            references portal.organization,
    name               varchar(255) NOT NULL,
    note               text,
    license_server_url text         NOT NULL,
    tsnotbefore         timestamptz  NOT NULL DEFAULT CURRENT_TIMESTAMP,
    tsnotafter             timestamptz NOT NULL,
    tscreated         timestamptz  NOT NULL DEFAULT CURRENT_TIMESTAMP,
    tsmodified         timestamptz  NOT NULL DEFAULT CURRENT_TIMESTAMP,
    tsapproved        timestamptz,
    tsrejected        timestamptz,
    tsexpack        timestamptz,
    license_days_valid  int NOT NULL
);

SQL queries

-- name: PurchaseOrderUpdate :exec
UPDATE portal.purchase_order
SET
    name = @name,
    note = @note,
    parent_id = @parent_id,
    license_server_url = @license_server_url,
    tsnotbefore = @tsnotbefore::timestamptz,
    tsnotafter = @tsnotafter::timestamptz,
    license_days_valid = @license_days_valid,
    tsmodified=CURRENT_TIMESTAMP,
    tsapproved = @tsapproved::timestamptz
WHERE uuid = @uuid
;

Configuration

version: "2"
sql:
  - engine: "postgresql"
    queries:
      - "query_license.sql"
    schema:
    - "schema.sql"
    - "../../../portal-backend/src/main/resources/db/migration/V1.0.6__licensing_v2_1.sql" #just for now
    database:
      uri: "postgres://portal:portal@localhost:49174/quarkus"
    gen:
      go:
        package: "db"
        out: "."
        sql_package: "pgx/v5"
        emit_result_struct_pointers: true
        emit_params_struct_pointers: true
        emit_pointers_for_null_types: true
        omit_unused_structs: true
        query_parameter_limit: 4
#        emit_sql_as_comment: true
#        emit_exact_table_names: true
        emit_methods_with_db_argument: true
        rename:
          license_server_url: "LicenseServerURL"
          uuid: "UUID"
        overrides:
          - db_type: "timestamptz"
            nullable: false
            go_type:
              type: "time.Time"
              pointer: false
          - db_type: "timestamptz"
            nullable: true
            go_type:
              type: "time.Time"
              pointer: true

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions