Skip to content

internal/dinosql: support Postgres macaddr type in Go #358

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

Merged
merged 1 commit into from
Feb 24, 2020
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
9 changes: 9 additions & 0 deletions internal/dinosql/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ func InterfaceImports(r Generateable, settings config.CombinedSettings) [][]stri
if uses("net.IP") {
std["net"] = struct{}{}
}
if uses("net.HardwareAddr") {
std["net"] = struct{}{}
}

pkg := make(map[string]struct{})
overrideTypes := map[string]string{}
Expand Down Expand Up @@ -298,6 +301,9 @@ func ModelImports(r Generateable, settings config.CombinedSettings) [][]string {
if UsesType(r, "net.IP", settings) {
std["net"] = struct{}{}
}
if UsesType(r, "net.HardwareAddr", settings) {
std["net"] = struct{}{}
}

// Custom imports
pkg := make(map[string]struct{})
Expand Down Expand Up @@ -693,6 +699,9 @@ func (r Result) goInnerType(col core.Column, settings config.CombinedSettings) s
case "inet":
return "net.IP"

case "macaddr", "macaddr8":
return "net.HardwareAddr"

case "void":
// A void value always returns NULL. Since there is no built-in NULL
// value into the SQL package, we'll use sql.NullBool
Expand Down
29 changes: 29 additions & 0 deletions internal/endtoend/testdata/macaddr/go/db.go

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

12 changes: 12 additions & 0 deletions internal/endtoend/testdata/macaddr/go/models.go

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

35 changes: 35 additions & 0 deletions internal/endtoend/testdata/macaddr/go/query.sql.go

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

4 changes: 4 additions & 0 deletions internal/endtoend/testdata/macaddr/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE foo (bar bool not null, addr macaddr not null);

-- name: Get :many
SELECT bar, addr FROM foo LIMIT $1;
9 changes: 9 additions & 0 deletions internal/endtoend/testdata/macaddr/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": "1",
"packages": [{
"path": "go",
"name": "querytest",
"schema": "query.sql",
"queries": "query.sql"
}]
}
2 changes: 1 addition & 1 deletion internal/endtoend/testdata/ondeck/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CREATE TYPE status AS ENUM ('open', 'closed');

CREATE TABLE venue (
id SERIAL primary key,
create_at timestamp not null,
create_at timestamp not null,
status status not null,
slug text not null,
name varchar(255) not null,
Expand Down