Fixed import paths for null package, add byte typ

This commit is contained in:
Patrick O'brien 2016-11-12 12:02:44 +10:00
parent 3d22dc0897
commit 86ca3bbcea
8 changed files with 47 additions and 26 deletions

View file

@ -317,6 +317,8 @@ func (p *PostgresDriver) TranslateColumnType(c bdb.Column) bdb.Column {
c.Type = "null.Float32" c.Type = "null.Float32"
case "bit", "interval", "bit varying", "character", "money", "character varying", "cidr", "inet", "macaddr", "text", "uuid", "xml": case "bit", "interval", "bit varying", "character", "money", "character varying", "cidr", "inet", "macaddr", "text", "uuid", "xml":
c.Type = "null.String" c.Type = "null.String"
case `"char"`:
c.Type = "null.Byte"
case "bytea": case "bytea":
c.Type = "null.Bytes" c.Type = "null.Bytes"
case "json", "jsonb": case "json", "jsonb":
@ -357,6 +359,8 @@ func (p *PostgresDriver) TranslateColumnType(c bdb.Column) bdb.Column {
c.Type = "float32" c.Type = "float32"
case "bit", "interval", "uuint", "bit varying", "character", "money", "character varying", "cidr", "inet", "macaddr", "text", "uuid", "xml": case "bit", "interval", "uuint", "bit varying", "character", "money", "character varying", "cidr", "inet", "macaddr", "text", "uuid", "xml":
c.Type = "string" c.Type = "string"
case `"char"`:
c.Type = "types.Byte"
case "json", "jsonb": case "json", "jsonb":
c.Type = "types.JSON" c.Type = "types.JSON"
case "bytea": case "bytea":

View file

@ -274,55 +274,55 @@ var defaultTestMainImports = map[string]imports{
// TranslateColumnType to see the type assignments. // TranslateColumnType to see the type assignments.
var importsBasedOnType = map[string]imports{ var importsBasedOnType = map[string]imports{
"null.Float32": { "null.Float32": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"null.Float64": { "null.Float64": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"null.Int": { "null.Int": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"null.Int8": { "null.Int8": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"null.Int16": { "null.Int16": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"null.Int32": { "null.Int32": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"null.Int64": { "null.Int64": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"null.Uint": { "null.Uint": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"null.Uint8": { "null.Uint8": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"null.Uint16": { "null.Uint16": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"null.Uint32": { "null.Uint32": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"null.Uint64": { "null.Uint64": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"null.String": { "null.String": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"null.Bool": { "null.Bool": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"null.Time": { "null.Time": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"null.JSON": { "null.JSON": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"null.Bytes": { "null.Bytes": {
thirdParty: importList{`"gopkg.in/nullbio/null.v5"`}, thirdParty: importList{`"gopkg.in/nullbio/null.v6"`},
}, },
"time.Time": { "time.Time": {
standard: importList{`"time"`}, standard: importList{`"time"`},

View file

@ -75,7 +75,7 @@ func TestCombineTypeImports(t *testing.T) {
}, },
thirdParty: importList{ thirdParty: importList{
`"github.com/vattle/sqlboiler/boil"`, `"github.com/vattle/sqlboiler/boil"`,
`"gopkg.in/nullbio/null.v5"`, `"gopkg.in/nullbio/null.v6"`,
}, },
} }
@ -108,7 +108,7 @@ func TestCombineTypeImports(t *testing.T) {
}, },
thirdParty: importList{ thirdParty: importList{
`"github.com/vattle/sqlboiler/boil"`, `"github.com/vattle/sqlboiler/boil"`,
`"gopkg.in/nullbio/null.v5"`, `"gopkg.in/nullbio/null.v6"`,
}, },
} }
@ -124,7 +124,7 @@ func TestCombineImports(t *testing.T) {
a := imports{ a := imports{
standard: importList{"fmt"}, standard: importList{"fmt"},
thirdParty: importList{"github.com/vattle/sqlboiler", "gopkg.in/nullbio/null.v5"}, thirdParty: importList{"github.com/vattle/sqlboiler", "gopkg.in/nullbio/null.v6"},
} }
b := imports{ b := imports{
standard: importList{"os"}, standard: importList{"os"},
@ -136,8 +136,8 @@ func TestCombineImports(t *testing.T) {
if c.standard[0] != "fmt" && c.standard[1] != "os" { if c.standard[0] != "fmt" && c.standard[1] != "os" {
t.Errorf("Wanted: fmt, os got: %#v", c.standard) t.Errorf("Wanted: fmt, os got: %#v", c.standard)
} }
if c.thirdParty[0] != "github.com/vattle/sqlboiler" && c.thirdParty[1] != "gopkg.in/nullbio/null.v5" { if c.thirdParty[0] != "github.com/vattle/sqlboiler" && c.thirdParty[1] != "gopkg.in/nullbio/null.v6" {
t.Errorf("Wanted: github.com/vattle/sqlboiler, gopkg.in/nullbio/null.v5 got: %#v", c.thirdParty) t.Errorf("Wanted: github.com/vattle/sqlboiler, gopkg.in/nullbio/null.v6 got: %#v", c.thirdParty)
} }
} }

View file

@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
"gopkg.in/nullbio/null.v5" null "gopkg.in/nullbio/null.v6"
) )
type testObj struct { type testObj struct {

View file

@ -12,7 +12,7 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"gopkg.in/nullbio/null.v5" null "gopkg.in/nullbio/null.v6"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/satori/go.uuid" "github.com/satori/go.uuid"

View file

@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
"gopkg.in/nullbio/null.v5" null "gopkg.in/nullbio/null.v6"
) )
func TestRandomizeStruct(t *testing.T) { func TestRandomizeStruct(t *testing.T) {

View file

@ -380,7 +380,7 @@ func MakeStringMap(types map[string]string) string {
c := 0 c := 0
for _, k := range keys { for _, k := range keys {
v := types[k] v := types[k]
buf.WriteString(fmt.Sprintf(`"%s": "%s"`, k, v)) buf.WriteString(fmt.Sprintf("`%s`: `%s`", k, v))
if c < len(types)-1 { if c < len(types)-1 {
buf.WriteString(", ") buf.WriteString(", ")
} }

View file

@ -24,6 +24,23 @@ CREATE TABLE magic (
string_ten VARCHAR(1000) NULL DEFAULT '', string_ten VARCHAR(1000) NULL DEFAULT '',
string_eleven VARCHAR(1000) NOT NULL DEFAULT '', string_eleven VARCHAR(1000) NOT NULL DEFAULT '',
nonbyte_zero CHAR(1),
nonbyte_one CHAR(1) NULL,
nonbyte_two CHAR(1) NOT NULL,
nonbyte_three CHAR(1) NULL DEFAULT 'a',
nonbyte_four CHAR(1) NOT NULL DEFAULT 'b',
nonbyte_five CHAR(1000),
nonbyte_six CHAR(1000) NULL,
nonbyte_seven CHAR(1000) NOT NULL,
nonbyte_eight CHAR(1000) NULL DEFAULT 'a',
nonbyte_nine CHAR(1000) NOT NULL DEFAULT 'b',
byte_zero "char",
byte_one "char" NULL,
byte_two "char" NOT NULL,
byte_three "char" NULL DEFAULT 'a',
byte_four "char" NOT NULL DEFAULT 'b',
big_int_zero bigint, big_int_zero bigint,
big_int_one bigint NULL, big_int_one bigint NULL,
big_int_two bigint NOT NULL, big_int_two bigint NOT NULL,