Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/faide/go-kallax
Browse files Browse the repository at this point in the history
  • Loading branch information
faide committed Jun 28, 2018
2 parents 02e8cd8 + c1d6c20 commit 46d7851
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
3 changes: 2 additions & 1 deletion benchmarks/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ func envOrDefault(key string, def string) string {

func dbURL() string {
return fmt.Sprintf(
"postgres://%s:%s@0.0.0.0:5432/%s?sslmode=disable",
"postgres://%s:%s@%s/%s?sslmode=disable",
envOrDefault("DBUSER", "testing"),
envOrDefault("DBPASS", "testing"),
envOrDefault("DBHOST", "0.0.0.0:5432"),
envOrDefault("DBNAME", "testing"),
)
}
Expand Down
3 changes: 2 additions & 1 deletion common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ func envOrDefault(key string, def string) string {

func openTestDB() (*sql.DB, error) {
return sql.Open("postgres", fmt.Sprintf(
"postgres://%s:%s@0.0.0.0:5432/%s?sslmode=disable",
"postgres://%s:%s@%s/%s?sslmode=disable",
envOrDefault("DBUSER", "testing"),
envOrDefault("DBPASS", "testing"),
envOrDefault("DBHOST", "0.0.0.0:5432"),
envOrDefault("DBNAME", "testing"),
))
}
Expand Down
16 changes: 2 additions & 14 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package kallax

import (
"bytes"
"crypto/rand"
"database/sql"
"database/sql/driver"
"encoding/hex"
"fmt"
"math/rand"
"sync"
"time"

"github.com/oklog/ulid"
Expand Down Expand Up @@ -227,13 +226,6 @@ type Record interface {
Saveable
}

var randPool = &sync.Pool{
New: func() interface{} {
seed := time.Now().UnixNano() + rand.Int63()
return rand.NewSource(seed)
},
}

// ULID is an ID type provided by kallax that is a lexically sortable UUID.
// The internal representation is an ULID (https://github.com/oklog/ulid).
// It already implements sql.Scanner and driver.Valuer, so it's perfectly
Expand All @@ -242,11 +234,7 @@ type ULID uuid.UUID

// NewULID returns a new ULID, which is a lexically sortable UUID.
func NewULID() ULID {
entropy := randPool.Get().(rand.Source)
id := ULID(ulid.MustNew(ulid.Timestamp(time.Now()), rand.New(entropy)))
randPool.Put(entropy)

return id
return ULID(ulid.MustNew(ulid.Timestamp(time.Now()), rand.Reader))
}

// NewULIDFromText creates a new ULID from its string representation. Will
Expand Down
3 changes: 2 additions & 1 deletion types/slices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,10 @@ func envOrDefault(key string, def string) string {

func openTestDB() (*sql.DB, error) {
return sql.Open("postgres", fmt.Sprintf(
"postgres://%s:%s@0.0.0.0:5432/%s?sslmode=disable",
"postgres://%s:%s@%s/%s?sslmode=disable",
envOrDefault("DBUSER", "testing"),
envOrDefault("DBPASS", "testing"),
envOrDefault("DBHOST", "0.0.0.0:5432"),
envOrDefault("DBNAME", "testing"),
))
}
12 changes: 10 additions & 2 deletions types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ func TestNullable(t *testing.T) {
PtrDuration *time.Duration
)
tim := time.Now().UTC()
tim = time.Date(tim.Year(), tim.Month(), tim.Day(), tim.Hour(), tim.Minute(), tim.Second(), 0, tim.Location())
tim = time.Date(tim.Year(), tim.Month(), tim.Day(), tim.Hour(),
tim.Minute(), tim.Second(), 0, tim.Location())
s := require.New(t)
url, err := url.Parse("http://foo.me")
s.NoError(err)
Expand Down Expand Up @@ -431,7 +432,14 @@ func TestNullable(t *testing.T) {
if c.isPtr {
elem = elem.Elem()
}
s.Equal(c.nonNullInput, elem.Interface(), c.name)

result := elem.Interface()
switch v := result.(type) {
case time.Time:
result = v.UTC()
}

s.Equal(c.nonNullInput, result, c.name)

_, err = db.Exec("DROP TABLE foo")
s.Nil(err, c.name)
Expand Down

0 comments on commit 46d7851

Please sign in to comment.