gen icon indicating copy to clipboard operation
gen copied to clipboard

Support for uuid and CHARACTER varying[] in Postgres database

Open GeekEast opened this issue 4 years ago • 4 comments

  • for DDL like this:
create table companies
(
    id                  uuid                default public.uuid_generate_v4() not null   constraint clients_pkey
    tags                character varying[] default '{}'::character varying[],
    deleted_by_id       uuid,
    created_by_id       uuid,
);
  • gen outputs errors like:
table: companies unable to generate struct field: id type: UUID error: unknown sql type: uuid
table: companies unable to generate struct field: tags type: _VARCHAR error: unknown sql type: _varchar
table: companies unable to generate struct field: deleted_by_id type: UUID error: unknown sql type: uuid
table: companies unable to generate struct field: created_by_id type: UUID error: unknown sql type: uuid

Issues

  • It seems like gen doesn't support the uuid type
  • It seems like gen doesn't support the CHARACTER Varying[] type

GeekEast avatar Jun 03 '20 00:06 GeekEast

Suggestion

  • for uuid, suggest to generate type as uuid.NullUUID
  • for CHARACTER varying
type Company struct {
    Tags sql.NullString `gorm:"column:tags;type:VARCHAR;default:'{}';" json:"tags"`
}

GeekEast avatar Jun 03 '20 01:06 GeekEast

@GeekEast I added uuid support for postgres handling it as a string - Looking into CHARACTER varying

alexj212 avatar Jun 07 '20 15:06 alexj212

CREATE TABLE order_details (
    order_id smallint NOT NULL,
    product_id smallint NOT NULL,
    unit_price real NOT NULL,
    quantity smallint NOT NULL,
    discount real NOT NULL
);

It seems like gen doesn't support the real type of Postgresql

table: order_details unable to generate struct field: unit_price type: FLOAT4 error: unknown sql type: float4
table: order_details unable to generate struct field: discount type: FLOAT4 error: unknown sql type: float4

dwgeneral avatar Jul 10 '20 07:07 dwgeneral

  • v0.9.23 (07/10/2020)
    • Added postgres types: bigserial, serial, smallserial, bigserial, float4 to mapping.json

alexj212 avatar Jul 10 '20 14:07 alexj212