Skip to content

Commit 16cc4e9

Browse files
authored
internal/dinosql: Add support for timestamptz (#169)
> 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.
1 parent b2fc73e commit 16cc4e9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

internal/dinosql/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ func (r Result) goInnerType(col core.Column) string {
537537
case "bytea", "blob", "pg_catalog.bytea":
538538
return "[]byte"
539539

540-
case "pg_catalog.timestamp", "pg_catalog.timestamptz":
540+
case "pg_catalog.timestamp", "pg_catalog.timestamptz", "timestamptz":
541541
if notNull {
542542
return "time.Time"
543543
}

internal/dinosql/gen_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,23 @@ func TestColumnsToStruct(t *testing.T) {
7575
t.Errorf("struct mismatch: \n%s", diff)
7676
}
7777
}
78+
79+
func TestInnerType(t *testing.T) {
80+
r := Result{}
81+
for _, tc := range []struct {
82+
col pg.Column
83+
expected string
84+
}{
85+
{
86+
pg.Column{Name: "created", DataType: "timestamptz", NotNull: true},
87+
"time.Time",
88+
},
89+
} {
90+
tt := tc
91+
t.Run(tt.col.Name+"-"+tt.col.DataType, func(t *testing.T) {
92+
if diff := cmp.Diff(tt.expected, r.goType(tt.col)); diff != "" {
93+
t.Errorf("struct mismatch: \n%s", diff)
94+
}
95+
})
96+
}
97+
}

0 commit comments

Comments
 (0)