Skip to content

Commit 0681ee3

Browse files
committed
Fix randomize functions for new sqlboiler
- Remove gopkg.in versioning
1 parent 56e0b74 commit 0681ee3

20 files changed

+72
-71
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Changelog
2+
3+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
4+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
5+
6+
## [v8.0.0]
7+
8+
### Changed
9+
10+
- Update code for new randomizer interface
11+
- Start versioning with semantic versions
12+
- Add tags for older versions (back to 7.1.0)

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ All types implement `sql.Scanner` and `driver.Valuer`, so you can use this libra
1010

1111
Install:
1212

13-
`go get -u "gopkg.in/volatiletech/null.v7"`
13+
Null used to be versioned with gopkg.in, so once you upgrade to v8 and beyond
14+
please stop using gopkg.in and ensure you're using `vgo`, `dep` or vendoring
15+
to version null.
16+
17+
`go get -u "github.com/volatiletech/null"`
1418

1519
### null package
1620

17-
`import "gopkg.in/volatiletech/null.v7"`
21+
`import "github.com/volatiletech/null"`
1822

1923
The following are all types supported in this package. All types will marshal to JSON null if Invalid or SQL source data is null.
2024

bool.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66
"encoding/json"
77
"errors"
88

9-
"github.com/volatiletech/sqlboiler/randomize"
10-
"gopkg.in/volatiletech/null.v7/convert"
9+
"github.com/volatiletech/null/convert"
1110
)
1211

1312
// Bool is a nullable bool.
@@ -134,12 +133,12 @@ func (b Bool) Value() (driver.Value, error) {
134133
}
135134

136135
// Randomize for sqlboiler
137-
func (b *Bool) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
136+
func (b *Bool) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) {
138137
if shouldBeNull {
139138
b.Bool = false
140139
b.Valid = false
141140
} else {
142-
b.Bool = seed.NextInt()%2 == 1
141+
b.Bool = nextInt()%2 == 1
143142
b.Valid = true
144143
}
145144
}

byte.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"database/sql/driver"
66
"encoding/json"
77
"errors"
8-
9-
"github.com/volatiletech/sqlboiler/randomize"
108
)
119

1210
// Byte is an nullable int.
@@ -137,12 +135,12 @@ func (b Byte) Value() (driver.Value, error) {
137135
}
138136

139137
// Randomize for sqlboiler
140-
func (b *Byte) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
138+
func (b *Byte) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) {
141139
if shouldBeNull {
142140
b.Byte = byte(0)
143141
b.Valid = false
144142
} else {
145-
b.Byte = byte(seed.NextInt()%60 + 65) // Ascii range
143+
b.Byte = byte(nextInt()%60 + 65) // Ascii range
146144
b.Valid = true
147145
}
148146
}

bytes.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import (
55
"database/sql/driver"
66
"encoding/json"
77

8-
"github.com/volatiletech/sqlboiler/randomize"
9-
"gopkg.in/volatiletech/null.v7/convert"
8+
"github.com/volatiletech/null/convert"
109
)
1110

1211
// NullBytes is a global byte slice of JSON null
@@ -125,12 +124,12 @@ func (b Bytes) Value() (driver.Value, error) {
125124
}
126125

127126
// Randomize for sqlboiler
128-
func (b *Bytes) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
127+
func (b *Bytes) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) {
129128
if shouldBeNull {
130129
b.Bytes = nil
131130
b.Valid = false
132131
} else {
133-
b.Bytes = []byte{byte(seed.NextInt() % 256)}
132+
b.Bytes = []byte{byte(nextInt() % 256)}
134133
b.Valid = true
135134
}
136135
}

float32.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66
"encoding/json"
77
"strconv"
88

9-
"github.com/volatiletech/sqlboiler/randomize"
10-
"gopkg.in/volatiletech/null.v7/convert"
9+
"github.com/volatiletech/null/convert"
1110
)
1211

1312
// Float32 is a nullable float32.
@@ -124,12 +123,12 @@ func (f Float32) Value() (driver.Value, error) {
124123
}
125124

126125
// Randomize for sqlboiler
127-
func (f *Float32) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
126+
func (f *Float32) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) {
128127
if shouldBeNull {
129128
f.Float32 = 0
130129
f.Valid = false
131130
} else {
132-
f.Float32 = float32(seed.NextInt()%10)/10.0 + float32(seed.NextInt()%10)
131+
f.Float32 = float32(nextInt()%10)/10.0 + float32(nextInt()%10)
133132
f.Valid = true
134133
}
135134
}

float64.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66
"encoding/json"
77
"strconv"
88

9-
"github.com/volatiletech/sqlboiler/randomize"
10-
"gopkg.in/volatiletech/null.v7/convert"
9+
"github.com/volatiletech/null/convert"
1110
)
1211

1312
// Float64 is a nullable float64.
@@ -119,12 +118,12 @@ func (f Float64) Value() (driver.Value, error) {
119118
}
120119

121120
// Randomize for sqlboiler
122-
func (f *Float64) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
121+
func (f *Float64) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) {
123122
if shouldBeNull {
124123
f.Float64 = 0
125124
f.Valid = false
126125
} else {
127-
f.Float64 = float64(seed.NextInt()%10)/10.0 + float64(seed.NextInt()%10)
126+
f.Float64 = float64(nextInt()%10)/10.0 + float64(nextInt()%10)
128127
f.Valid = true
129128
}
130129
}

int.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import (
77
"math"
88
"strconv"
99

10-
"github.com/volatiletech/sqlboiler/randomize"
11-
"gopkg.in/volatiletech/null.v7/convert"
10+
"github.com/volatiletech/null/convert"
1211
)
1312

1413
// Int is an nullable int.
@@ -125,12 +124,12 @@ func (i Int) Value() (driver.Value, error) {
125124
}
126125

127126
// Randomize for sqlboiler
128-
func (i *Int) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
127+
func (i *Int) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) {
129128
if shouldBeNull {
130129
i.Int = 0
131130
i.Valid = false
132131
} else {
133-
i.Int = int(int32(seed.NextInt() % math.MaxInt32))
132+
i.Int = int(int32(nextInt() % math.MaxInt32))
134133
i.Valid = true
135134
}
136135
}

int16.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88
"math"
99
"strconv"
1010

11-
"github.com/volatiletech/sqlboiler/randomize"
12-
"gopkg.in/volatiletech/null.v7/convert"
11+
"github.com/volatiletech/null/convert"
1312
)
1413

1514
// Int16 is an nullable int16.
@@ -130,12 +129,12 @@ func (i Int16) Value() (driver.Value, error) {
130129
}
131130

132131
// Randomize for sqlboiler
133-
func (i *Int16) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
132+
func (i *Int16) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) {
134133
if shouldBeNull {
135134
i.Int16 = 0
136135
i.Valid = false
137136
} else {
138-
i.Int16 = int16(seed.NextInt() % math.MaxInt16)
137+
i.Int16 = int16(nextInt() % math.MaxInt16)
139138
i.Valid = true
140139
}
141140
}

int32.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"math"
99
"strconv"
1010

11+
"github.com/volatiletech/null/convert"
1112
"github.com/volatiletech/sqlboiler/randomize"
12-
"gopkg.in/volatiletech/null.v7/convert"
1313
)
1414

1515
// Int32 is an nullable int32.
@@ -130,16 +130,16 @@ func (i Int32) Value() (driver.Value, error) {
130130
}
131131

132132
// Randomize for sqlboiler
133-
func (i *Int32) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
133+
func (i *Int32) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) {
134134
if shouldBeNull {
135135
i.Int32 = 0
136136
i.Valid = false
137137
} else {
138-
val, ok := randomize.MediumInt(seed, fieldType)
138+
val, ok := randomize.MediumInt(nextInt, fieldType)
139139
if ok {
140140
i.Int32 = val
141141
} else {
142-
i.Int32 = int32(seed.NextInt() % math.MaxInt32)
142+
i.Int32 = int32(nextInt() % math.MaxInt32)
143143
}
144144

145145
i.Valid = true

int64.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66
"encoding/json"
77
"strconv"
88

9-
"github.com/volatiletech/sqlboiler/randomize"
10-
"gopkg.in/volatiletech/null.v7/convert"
9+
"github.com/volatiletech/null/convert"
1110
)
1211

1312
// Int64 is an nullable int64.
@@ -119,12 +118,12 @@ func (i Int64) Value() (driver.Value, error) {
119118
}
120119

121120
// Randomize for sqlboiler
122-
func (i *Int64) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
121+
func (i *Int64) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) {
123122
if shouldBeNull {
124123
i.Int64 = 0
125124
i.Valid = false
126125
} else {
127-
i.Int64 = int64(seed.NextInt())
126+
i.Int64 = int64(nextInt())
128127
i.Valid = true
129128
}
130129
}

int8.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88
"math"
99
"strconv"
1010

11-
"github.com/volatiletech/sqlboiler/randomize"
12-
"gopkg.in/volatiletech/null.v7/convert"
11+
"github.com/volatiletech/null/convert"
1312
)
1413

1514
// Int8 is an nullable int8.
@@ -130,12 +129,12 @@ func (i Int8) Value() (driver.Value, error) {
130129
}
131130

132131
// Randomize for sqlboiler
133-
func (i *Int8) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
132+
func (i *Int8) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) {
134133
if shouldBeNull {
135134
i.Int8 = 0
136135
i.Valid = false
137136
} else {
138-
i.Int8 = int8(seed.NextInt() % math.MaxInt8)
137+
i.Int8 = int8(nextInt() % math.MaxInt8)
139138
i.Valid = true
140139
}
141140
}

json.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"errors"
88
"fmt"
99

10+
"github.com/volatiletech/null/convert"
1011
"github.com/volatiletech/sqlboiler/randomize"
11-
"gopkg.in/volatiletech/null.v7/convert"
1212
)
1313

1414
// JSON is a nullable []byte.
@@ -158,7 +158,7 @@ func (j JSON) Value() (driver.Value, error) {
158158
}
159159

160160
// Randomize for sqlboiler
161-
func (j *JSON) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
162-
j.JSON = []byte(`"` + randomize.Str(seed, 1) + `"`)
161+
func (j *JSON) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) {
162+
j.JSON = []byte(`"` + randomize.Str(nextInt, 1) + `"`)
163163
j.Valid = true
164164
}

string.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"database/sql/driver"
66
"encoding/json"
77

8+
"github.com/volatiletech/null/convert"
89
"github.com/volatiletech/sqlboiler/randomize"
9-
"gopkg.in/volatiletech/null.v7/convert"
1010
)
1111

1212
// String is a nullable string. It supports SQL and JSON serialization.
@@ -118,8 +118,8 @@ func (s String) Value() (driver.Value, error) {
118118
}
119119

120120
// Randomize for sqlboiler
121-
func (s *String) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
122-
str, ok := randomize.FormattedString(seed, fieldType)
121+
func (s *String) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) {
122+
str, ok := randomize.FormattedString(nextInt, fieldType)
123123
if ok {
124124
s.String = str
125125
s.Valid = true
@@ -130,7 +130,7 @@ func (s *String) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull
130130
s.String = ""
131131
s.Valid = false
132132
} else {
133-
s.String = randomize.Str(seed, 1)
133+
s.String = randomize.Str(nextInt, 1)
134134
s.Valid = true
135135
}
136136
}

time.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ func (t Time) Value() (driver.Value, error) {
120120
}
121121

122122
// Randomize for sqlboiler
123-
func (t *Time) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
123+
func (t *Time) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) {
124124
if shouldBeNull {
125125
t.Time = time.Time{}
126126
t.Valid = false
127127
} else {
128-
t.Time = randomize.Date(seed)
128+
t.Time = randomize.Date(nextInt)
129129
t.Valid = true
130130
}
131131
}

uint.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66
"encoding/json"
77
"strconv"
88

9-
"github.com/volatiletech/sqlboiler/randomize"
10-
"gopkg.in/volatiletech/null.v7/convert"
9+
"github.com/volatiletech/null/convert"
1110
)
1211

1312
// Uint is an nullable uint.
@@ -124,12 +123,12 @@ func (u Uint) Value() (driver.Value, error) {
124123
}
125124

126125
// Randomize for sqlboiler
127-
func (u *Uint) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
126+
func (u *Uint) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) {
128127
if shouldBeNull {
129128
u.Uint = 0
130129
u.Valid = false
131130
} else {
132-
u.Uint = uint(seed.NextInt())
131+
u.Uint = uint(nextInt())
133132
u.Valid = true
134133
}
135134
}

uint16.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88
"math"
99
"strconv"
1010

11-
"github.com/volatiletech/sqlboiler/randomize"
12-
"gopkg.in/volatiletech/null.v7/convert"
11+
"github.com/volatiletech/null/convert"
1312
)
1413

1514
// Uint16 is an nullable uint16.
@@ -130,12 +129,12 @@ func (u Uint16) Value() (driver.Value, error) {
130129
}
131130

132131
// Randomize for sqlboiler
133-
func (u *Uint16) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
132+
func (u *Uint16) Randomize(nextInt func() int64, fieldType string, shouldBeNull bool) {
134133
if shouldBeNull {
135134
u.Uint16 = 0
136135
u.Valid = false
137136
} else {
138-
u.Uint16 = uint16(seed.NextInt() % math.MaxUint16)
137+
u.Uint16 = uint16(nextInt() % math.MaxUint16)
139138
u.Valid = true
140139
}
141140
}

0 commit comments

Comments
 (0)