Skip to content

Commit 3edeba8

Browse files
egtannEvan Tann
andauthored
feat(postgres): Add support for sql.NullInt16 (#1376)
* feat(postgres): Add support for sql.NullInt16 * bump go.mod to 1.17 Co-authored-by: Evan Tann <[email protected]>
1 parent cea1420 commit 3edeba8

File tree

10 files changed

+44
-19
lines changed

10 files changed

+44
-19
lines changed

go.mod

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/kyleconroy/sqlc
22

3-
go 1.16
3+
go 1.17
44

55
require (
66
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211208212222-82c441726976
@@ -9,15 +9,34 @@ require (
99
github.com/google/go-cmp v0.5.6
1010
github.com/jackc/pgx/v4 v4.14.1
1111
github.com/jinzhu/inflection v1.0.0
12-
github.com/kr/pretty v0.2.1 // indirect
1312
github.com/lib/pq v1.10.4
1413
github.com/pganalyze/pg_query_go/v2 v2.1.0
15-
github.com/pingcap/log v0.0.0-20210906054005-afc726e70354 // indirect
1614
github.com/pingcap/parser v0.0.0-20210914110036-002913dd28ec
17-
github.com/pkg/errors v0.9.1 // indirect
1815
github.com/spf13/cobra v1.3.0
1916
github.com/spf13/pflag v1.0.5
20-
go.uber.org/zap v1.19.1 // indirect
2117
google.golang.org/protobuf v1.27.1
2218
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
2319
)
20+
21+
require (
22+
github.com/golang/protobuf v1.5.2 // indirect
23+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
24+
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
25+
github.com/jackc/pgconn v1.10.1 // indirect
26+
github.com/jackc/pgio v1.0.0 // indirect
27+
github.com/jackc/pgpassfile v1.0.0 // indirect
28+
github.com/jackc/pgproto3/v2 v2.2.0 // indirect
29+
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
30+
github.com/jackc/pgtype v1.9.1 // indirect
31+
github.com/kr/pretty v0.2.1 // indirect
32+
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63 // indirect
33+
github.com/pingcap/log v0.0.0-20210906054005-afc726e70354 // indirect
34+
github.com/pkg/errors v0.9.1 // indirect
35+
go.uber.org/atomic v1.9.0 // indirect
36+
go.uber.org/multierr v1.7.0 // indirect
37+
go.uber.org/zap v1.19.1 // indirect
38+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
39+
golang.org/x/text v0.3.7 // indirect
40+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
41+
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
42+
)

internal/codegen/golang/postgresql_type.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ func postgresType(r *compiler.Result, col *compiler.Column, settings config.Comb
2828
return "sql.NullInt64"
2929

3030
case "smallserial", "serial2", "pg_catalog.serial2":
31-
return "int16"
31+
if notNull {
32+
return "int16"
33+
}
34+
return "sql.NullInt16"
3235

3336
case "integer", "int", "int4", "pg_catalog.int4":
3437
if notNull {
@@ -43,7 +46,10 @@ func postgresType(r *compiler.Result, col *compiler.Column, settings config.Comb
4346
return "sql.NullInt64"
4447

4548
case "smallint", "int2", "pg_catalog.int2":
46-
return "int16"
49+
if notNull {
50+
return "int16"
51+
}
52+
return "sql.NullInt16"
4753

4854
case "float", "double precision", "float8", "pg_catalog.float8":
4955
if notNull {

internal/endtoend/testdata/datatype/pgx/go/models.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/datatype/stdlib/go/models.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/json_tags/camel_case/postgresql/pgx/go/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/json_tags/camel_case/postgresql/stdlib/go/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/json_tags/pascal_case/postgresql/pgx/go/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/json_tags/pascal_case/postgresql/stdlib/go/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/json_tags/snake_case/postgresql/pgx/go/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/json_tags/snake_case/postgresql/stdlib/go/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)