From 5b30c01b62b140751870b53ef5c66894f0180ef2 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Fri, 13 Dec 2019 16:31:31 -0800 Subject: [PATCH] internal/dinosql: Add support for timestamptz > The SQL standard requires that writing just timestamp be equivalent to > timestamp without time zone, and PostgreSQL honors that behavior. > timestamptz is accepted as an abbreviation for timestamp with time zone; > this is a PostgreSQL extension. --- internal/dinosql/gen.go | 2 +- internal/dinosql/gen_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/internal/dinosql/gen.go b/internal/dinosql/gen.go index 54d678d47e..d26691750e 100644 --- a/internal/dinosql/gen.go +++ b/internal/dinosql/gen.go @@ -537,7 +537,7 @@ func (r Result) goInnerType(col core.Column) string { case "bytea", "blob", "pg_catalog.bytea": return "[]byte" - case "pg_catalog.timestamp", "pg_catalog.timestamptz": + case "pg_catalog.timestamp", "pg_catalog.timestamptz", "timestamptz": if notNull { return "time.Time" } diff --git a/internal/dinosql/gen_test.go b/internal/dinosql/gen_test.go index 9b366a08a4..16846b84cc 100644 --- a/internal/dinosql/gen_test.go +++ b/internal/dinosql/gen_test.go @@ -75,3 +75,23 @@ func TestColumnsToStruct(t *testing.T) { t.Errorf("struct mismatch: \n%s", diff) } } + +func TestInnerType(t *testing.T) { + r := Result{} + for _, tc := range []struct { + col pg.Column + expected string + }{ + { + pg.Column{Name: "created", DataType: "timestamptz", NotNull: true}, + "time.Time", + }, + } { + tt := tc + t.Run(tt.col.Name+"-"+tt.col.DataType, func(t *testing.T) { + if diff := cmp.Diff(tt.expected, r.goType(tt.col)); diff != "" { + t.Errorf("struct mismatch: \n%s", diff) + } + }) + } +}