Skip to content

Commit b344b07

Browse files
committed
internal/dinosql: Add DATE support
1 parent 40c71de commit b344b07

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

internal/dinosql/gen.go

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

555-
case "pg_catalog.timestamp", "pg_catalog.timestamptz", "timestamptz":
555+
case "pg_catalog.timestamp", "pg_catalog.timestamptz", "timestamptz", "date":
556556
if notNull {
557557
return "time.Time"
558558
}

internal/dinosql/gen_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func TestInnerType(t *testing.T) {
9797
"integer": "int32",
9898
"int": "int32",
9999
"pg_catalog.int4": "int32",
100+
"date": "time.Time",
100101
}
101102
for k, v := range types {
102103
dbType := k
@@ -117,6 +118,7 @@ func TestNullInnerType(t *testing.T) {
117118
"integer": "sql.NullInt32",
118119
"int": "sql.NullInt32",
119120
"pg_catalog.int4": "sql.NullInt32",
121+
"date": "sql.NullTime",
120122
}
121123
for k, v := range types {
122124
dbType := k

internal/dinosql/query_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,18 @@ func TestQueries(t *testing.T) {
813813
SQL: "SELECT a, b, c, d FROM foo, bar",
814814
},
815815
},
816+
{
817+
"date",
818+
`
819+
CREATE TABLE users ( birthday DATE );
820+
SELECT birthday FROM users;
821+
`,
822+
Query{
823+
Columns: []core.Column{
824+
{Table: public("users"), Name: "birthday", DataType: "date"},
825+
},
826+
},
827+
},
816828
} {
817829
test := tc
818830
t.Run(test.name, func(t *testing.T) {

0 commit comments

Comments
 (0)