Skip to content

Commit e190be4

Browse files
committed
internal/dinosql: support Postgres macaddr type in Go
Fixes #353.
1 parent 4b756bb commit e190be4

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
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/ondeck/models.go

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

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

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

internal/endtoend/testdata/ondeck/schema.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ 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,
1414
city text not null references city(slug),
1515
spotify_playlist varchar not null,
16-
songkick_id text
16+
songkick_id text,
17+
venue_ip inet,
18+
mac macaddr
1719
);

0 commit comments

Comments
 (0)