Skip to content

Commit

Permalink
When using pgx, map numeric types to pgtype.Numeric (sqlc-dev#1143)
Browse files Browse the repository at this point in the history
* endtoend: Consolidate test cases

* codegen/golang: numeric -> pgtype.Numeric for pgx

Fix the regenration script to always pass the `experimental` flag.
  • Loading branch information
kyleconroy authored Aug 23, 2021
1 parent ca0f3de commit 3114339
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 414 deletions.
1 change: 1 addition & 0 deletions internal/codegen/golang/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ var pgtypeTypes = map[string]struct{}{
"pgtype.CIDR": {},
"pgtype.Inet": {},
"pgtype.Macaddr": {},
"pgtype.Numeric": {},
}

var pqtypeTypes = map[string]struct{}{
Expand Down
3 changes: 3 additions & 0 deletions internal/codegen/golang/postgresql_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func postgresType(r *compiler.Result, col *compiler.Column, settings config.Comb
return "sql.NullFloat64" // TODO: Change to sql.NullFloat32 after updating the go.mod file

case "numeric", "pg_catalog.numeric", "money":
if driver == SQLDriverPGXV4 {
return "pgtype.Numeric"
}
// Since the Go standard library does not have a decimal type, lib/pq
// returns numerics as strings.
//
Expand Down
22 changes: 18 additions & 4 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.

13 changes: 13 additions & 0 deletions internal/endtoend/testdata/datatype/pgx/sql/net-types.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Network Address Types
-- https://www.postgresql.org/docs/current/datatype-net-types.html
CREATE TABLE dt_net_types (
a inet,
b cidr,
c macaddr
);

CREATE TABLE dt_net_types_not_null (
a inet NOT NULL,
b cidr NOT NULL,
c macaddr NOT NULL
);
14 changes: 14 additions & 0 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.

13 changes: 13 additions & 0 deletions internal/endtoend/testdata/datatype/stdlib/sql/net-types.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Network Address Types
-- https://www.postgresql.org/docs/current/datatype-net-types.html
CREATE TABLE dt_net_types (
a inet,
b cidr,
c macaddr
);

CREATE TABLE dt_net_types_not_null (
a inet NOT NULL,
b cidr NOT NULL,
c macaddr NOT NULL
);

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.

30 changes: 0 additions & 30 deletions internal/endtoend/testdata/types_network_address/pgx/go/db.go

This file was deleted.

19 changes: 0 additions & 19 deletions internal/endtoend/testdata/types_network_address/pgx/go/models.go

This file was deleted.

109 changes: 0 additions & 109 deletions internal/endtoend/testdata/types_network_address/pgx/go/query.sql.go

This file was deleted.

29 changes: 0 additions & 29 deletions internal/endtoend/testdata/types_network_address/pgx/query.sql

This file was deleted.

13 changes: 0 additions & 13 deletions internal/endtoend/testdata/types_network_address/pgx/sqlc.json

This file was deleted.

Loading

0 comments on commit 3114339

Please sign in to comment.