Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(postgres): Add support for sql.NullInt16 #1376

Merged
merged 4 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/kyleconroy/sqlc

go 1.16
go 1.17

require (
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211208212222-82c441726976
Expand All @@ -9,15 +9,34 @@ require (
github.com/google/go-cmp v0.5.6
github.com/jackc/pgx/v4 v4.14.1
github.com/jinzhu/inflection v1.0.0
github.com/kr/pretty v0.2.1 // indirect
github.com/lib/pq v1.10.4
github.com/pganalyze/pg_query_go/v2 v2.1.0
github.com/pingcap/log v0.0.0-20210906054005-afc726e70354 // indirect
github.com/pingcap/parser v0.0.0-20210914110036-002913dd28ec
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/cobra v1.3.0
github.com/spf13/pflag v1.0.5
go.uber.org/zap v1.19.1 // indirect
google.golang.org/protobuf v1.27.1
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)

require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.10.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.2.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.9.1 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63 // indirect
github.com/pingcap/log v0.0.0-20210906054005-afc726e70354 // indirect
github.com/pkg/errors v0.9.1 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.19.1 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
)
10 changes: 8 additions & 2 deletions internal/codegen/golang/postgresql_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ func postgresType(r *compiler.Result, col *compiler.Column, settings config.Comb
return "sql.NullInt64"

case "smallserial", "serial2", "pg_catalog.serial2":
return "int16"
if notNull {
return "int16"
}
return "sql.NullInt16"

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

case "smallint", "int2", "pg_catalog.int2":
return "int16"
if notNull {
return "int16"
}
return "sql.NullInt16"

case "float", "double precision", "float8", "pg_catalog.float8":
if notNull {
Expand Down
6 changes: 3 additions & 3 deletions internal/endtoend/testdata/datatype/pgx/go/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions internal/endtoend/testdata/datatype/stdlib/go/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.