diff --git a/json/transformer.go b/json/transformer.go index a62012dd..c039cc9d 100644 --- a/json/transformer.go +++ b/json/transformer.go @@ -18,22 +18,37 @@ func (t *ReverseTransformer) ReverseTransformValues(table *schema.Table, values type Transformer struct{} func (*Transformer) TransformBool(v *schema.Bool) any { + if v.Status != schema.Present { + return nil + } return v.Bool } func (*Transformer) TransformBytea(v *schema.Bytea) any { + if v.Status != schema.Present { + return nil + } return v.String() } func (*Transformer) TransformFloat8(v *schema.Float8) any { + if v.Status != schema.Present { + return nil + } return v.Float } func (*Transformer) TransformInt8(v *schema.Int8) any { + if v.Status != schema.Present { + return nil + } return v.Int } func (*Transformer) TransformInt8Array(v *schema.Int8Array) any { + if v.Status != schema.Present { + return nil + } res := make([]int64, len(v.Elements)) for i, e := range v.Elements { res[i] = e.Int @@ -42,6 +57,9 @@ func (*Transformer) TransformInt8Array(v *schema.Int8Array) any { } func (*Transformer) TransformJSON(v *schema.JSON) any { + if v.Status != schema.Present { + return nil + } var res any if err := json.Unmarshal(v.Bytes, &res); err != nil { panic(err) @@ -50,10 +68,16 @@ func (*Transformer) TransformJSON(v *schema.JSON) any { } func (*Transformer) TransformText(v *schema.Text) any { + if v.Status != schema.Present { + return nil + } return v.Str } func (*Transformer) TransformTextArray(v *schema.TextArray) any { + if v.Status != schema.Present { + return nil + } res := make([]string, len(v.Elements)) for i, e := range v.Elements { res[i] = e.Str @@ -62,14 +86,23 @@ func (*Transformer) TransformTextArray(v *schema.TextArray) any { } func (*Transformer) TransformTimestamptz(v *schema.Timestamptz) any { + if v.Status != schema.Present { + return nil + } return v.String() } func (*Transformer) TransformUUID(v *schema.UUID) any { + if v.Status != schema.Present { + return nil + } return v.String() } func (*Transformer) TransformUUIDArray(v *schema.UUIDArray) any { + if v.Status != schema.Present { + return nil + } res := make([]string, len(v.Elements)) for i, e := range v.Elements { res[i] = e.String() @@ -78,10 +111,16 @@ func (*Transformer) TransformUUIDArray(v *schema.UUIDArray) any { } func (*Transformer) TransformCIDR(v *schema.CIDR) any { + if v.Status != schema.Present { + return nil + } return v.String() } func (*Transformer) TransformCIDRArray(v *schema.CIDRArray) any { + if v.Status != schema.Present { + return nil + } res := make([]string, len(v.Elements)) for i, e := range v.Elements { res[i] = e.String() @@ -90,10 +129,16 @@ func (*Transformer) TransformCIDRArray(v *schema.CIDRArray) any { } func (*Transformer) TransformInet(v *schema.Inet) any { + if v.Status != schema.Present { + return nil + } return v.String() } func (*Transformer) TransformInetArray(v *schema.InetArray) any { + if v.Status != schema.Present { + return nil + } res := make([]string, len(v.Elements)) for i, e := range v.Elements { res[i] = e.String() @@ -102,10 +147,16 @@ func (*Transformer) TransformInetArray(v *schema.InetArray) any { } func (*Transformer) TransformMacaddr(v *schema.Macaddr) any { + if v.Status != schema.Present { + return nil + } return v.String() } func (*Transformer) TransformMacaddrArray(v *schema.MacaddrArray) any { + if v.Status != schema.Present { + return nil + } res := make([]string, len(v.Elements)) for i, e := range v.Elements { res[i] = e.String()