Skip to content

Commit d2823f5

Browse files
authored
internal/dinosql: support Postgres macaddr type in Go (#358)
Also add an end to end test. Fixes #353.
1 parent 4b756bb commit d2823f5

File tree

7 files changed

+99
-1
lines changed

7 files changed

+99
-1
lines changed

internal/dinosql/gen.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ func InterfaceImports(r Generateable, settings config.CombinedSettings) [][]stri
243243
if uses("net.IP") {
244244
std["net"] = struct{}{}
245245
}
246+
if uses("net.HardwareAddr") {
247+
std["net"] = struct{}{}
248+
}
246249

247250
pkg := make(map[string]struct{})
248251
overrideTypes := map[string]string{}
@@ -298,6 +301,9 @@ func ModelImports(r Generateable, settings config.CombinedSettings) [][]string {
298301
if UsesType(r, "net.IP", settings) {
299302
std["net"] = struct{}{}
300303
}
304+
if UsesType(r, "net.HardwareAddr", settings) {
305+
std["net"] = struct{}{}
306+
}
301307

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

702+
case "macaddr", "macaddr8":
703+
return "net.HardwareAddr"
704+
696705
case "void":
697706
// A void value always returns NULL. Since there is no built-in NULL
698707
// value into the SQL package, we'll use sql.NullBool

internal/endtoend/testdata/macaddr/go/db.go

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

internal/endtoend/testdata/macaddr/go/models.go

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

internal/endtoend/testdata/macaddr/go/query.sql.go

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CREATE TABLE foo (bar bool not null, addr macaddr not null);
2+
3+
-- name: Get :many
4+
SELECT bar, addr FROM foo LIMIT $1;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": "1",
3+
"packages": [{
4+
"path": "go",
5+
"name": "querytest",
6+
"schema": "query.sql",
7+
"queries": "query.sql"
8+
}]
9+
}

internal/endtoend/testdata/ondeck/schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CREATE TYPE status AS ENUM ('open', 'closed');
77

88
CREATE TABLE venue (
99
id SERIAL primary key,
10-
create_at timestamp not null,
10+
create_at timestamp not null,
1111
status status not null,
1212
slug text not null,
1313
name varchar(255) not null,

0 commit comments

Comments
 (0)