aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/jmoiron
diff options
context:
space:
mode:
authorFelix Hanley <felix@userspace.com.au>2018-01-03 13:21:23 +0000
committerFelix Hanley <felix@userspace.com.au>2018-01-03 13:21:23 +0000
commitc428d3bbcd66b64d55297a772cb71ed5e0767614 (patch)
tree5513824ce32bb59c9e0d786959de91d73c8a7e33 /vendor/github.com/jmoiron
parent9e19584ff19a9dbdf6c024e21ff29383400fa80f (diff)
downloaddhtsearch-c428d3bbcd66b64d55297a772cb71ed5e0767614.tar.gz
dhtsearch-c428d3bbcd66b64d55297a772cb71ed5e0767614.tar.bz2
Update deps
Diffstat (limited to 'vendor/github.com/jmoiron')
-rw-r--r--vendor/github.com/jmoiron/sqlx/types/README.md5
-rw-r--r--vendor/github.com/jmoiron/sqlx/types/types.go172
-rw-r--r--vendor/github.com/jmoiron/sqlx/types/types_test.go127
3 files changed, 0 insertions, 304 deletions
diff --git a/vendor/github.com/jmoiron/sqlx/types/README.md b/vendor/github.com/jmoiron/sqlx/types/README.md
deleted file mode 100644
index 713abe5..0000000
--- a/vendor/github.com/jmoiron/sqlx/types/README.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# types
-
-The types package provides some useful types which implement the `sql.Scanner`
-and `driver.Valuer` interfaces, suitable for use as scan and value targets with
-database/sql.
diff --git a/vendor/github.com/jmoiron/sqlx/types/types.go b/vendor/github.com/jmoiron/sqlx/types/types.go
deleted file mode 100644
index 7b014c1..0000000
--- a/vendor/github.com/jmoiron/sqlx/types/types.go
+++ /dev/null
@@ -1,172 +0,0 @@
-package types
-
-import (
- "bytes"
- "compress/gzip"
- "database/sql/driver"
- "encoding/json"
- "errors"
-
- "io/ioutil"
-)
-
-// GzippedText is a []byte which transparently gzips data being submitted to
-// a database and ungzips data being Scanned from a database.
-type GzippedText []byte
-
-// Value implements the driver.Valuer interface, gzipping the raw value of
-// this GzippedText.
-func (g GzippedText) Value() (driver.Value, error) {
- b := make([]byte, 0, len(g))
- buf := bytes.NewBuffer(b)
- w := gzip.NewWriter(buf)
- w.Write(g)
- w.Close()
- return buf.Bytes(), nil
-
-}
-
-// Scan implements the sql.Scanner interface, ungzipping the value coming off
-// the wire and storing the raw result in the GzippedText.
-func (g *GzippedText) Scan(src interface{}) error {
- var source []byte
- switch src.(type) {
- case string:
- source = []byte(src.(string))
- case []byte:
- source = src.([]byte)
- default:
- return errors.New("Incompatible type for GzippedText")
- }
- reader, err := gzip.NewReader(bytes.NewReader(source))
- if err != nil {
- return err
- }
- defer reader.Close()
- b, err := ioutil.ReadAll(reader)
- if err != nil {
- return err
- }
- *g = GzippedText(b)
- return nil
-}
-
-// JSONText is a json.RawMessage, which is a []byte underneath.
-// Value() validates the json format in the source, and returns an error if
-// the json is not valid. Scan does no validation. JSONText additionally
-// implements `Unmarshal`, which unmarshals the json within to an interface{}
-type JSONText json.RawMessage
-
-var emptyJSON = JSONText("{}")
-
-// MarshalJSON returns the *j as the JSON encoding of j.
-func (j JSONText) MarshalJSON() ([]byte, error) {
- if len(j) == 0 {
- return emptyJSON, nil
- }
- return j, nil
-}
-
-// UnmarshalJSON sets *j to a copy of data
-func (j *JSONText) UnmarshalJSON(data []byte) error {
- if j == nil {
- return errors.New("JSONText: UnmarshalJSON on nil pointer")
- }
- *j = append((*j)[0:0], data...)
- return nil
-}
-
-// Value returns j as a value. This does a validating unmarshal into another
-// RawMessage. If j is invalid json, it returns an error.
-func (j JSONText) Value() (driver.Value, error) {
- var m json.RawMessage
- var err = j.Unmarshal(&m)
- if err != nil {
- return []byte{}, err
- }
- return []byte(j), nil
-}
-
-// Scan stores the src in *j. No validation is done.
-func (j *JSONText) Scan(src interface{}) error {
- var source []byte
- switch t := src.(type) {
- case string:
- source = []byte(t)
- case []byte:
- if len(t) == 0 {
- source = emptyJSON
- } else {
- source = t
- }
- case nil:
- *j = emptyJSON
- default:
- return errors.New("Incompatible type for JSONText")
- }
- *j = JSONText(append((*j)[0:0], source...))
- return nil
-}
-
-// Unmarshal unmarshal's the json in j to v, as in json.Unmarshal.
-func (j *JSONText) Unmarshal(v interface{}) error {
- if len(*j) == 0 {
- *j = emptyJSON
- }
- return json.Unmarshal([]byte(*j), v)
-}
-
-// String supports pretty printing for JSONText types.
-func (j JSONText) String() string {
- return string(j)
-}
-
-// NullJSONText represents a JSONText that may be null.
-// NullJSONText implements the scanner interface so
-// it can be used as a scan destination, similar to NullString.
-type NullJSONText struct {
- JSONText
- Valid bool // Valid is true if JSONText is not NULL
-}
-
-// Scan implements the Scanner interface.
-func (n *NullJSONText) Scan(value interface{}) error {
- if value == nil {
- n.JSONText, n.Valid = emptyJSON, false
- return nil
- }
- n.Valid = true
- return n.JSONText.Scan(value)
-}
-
-// Value implements the driver Valuer interface.
-func (n NullJSONText) Value() (driver.Value, error) {
- if !n.Valid {
- return nil, nil
- }
- return n.JSONText.Value()
-}
-
-// BitBool is an implementation of a bool for the MySQL type BIT(1).
-// This type allows you to avoid wasting an entire byte for MySQL's boolean type TINYINT.
-type BitBool bool
-
-// Value implements the driver.Valuer interface,
-// and turns the BitBool into a bitfield (BIT(1)) for MySQL storage.
-func (b BitBool) Value() (driver.Value, error) {
- if b {
- return []byte{1}, nil
- }
- return []byte{0}, nil
-}
-
-// Scan implements the sql.Scanner interface,
-// and turns the bitfield incoming from MySQL into a BitBool
-func (b *BitBool) Scan(src interface{}) error {
- v, ok := src.([]byte)
- if !ok {
- return errors.New("bad []byte type assertion")
- }
- *b = v[0] == 1
- return nil
-}
diff --git a/vendor/github.com/jmoiron/sqlx/types/types_test.go b/vendor/github.com/jmoiron/sqlx/types/types_test.go
deleted file mode 100644
index 29813d1..0000000
--- a/vendor/github.com/jmoiron/sqlx/types/types_test.go
+++ /dev/null
@@ -1,127 +0,0 @@
-package types
-
-import "testing"
-
-func TestGzipText(t *testing.T) {
- g := GzippedText("Hello, world")
- v, err := g.Value()
- if err != nil {
- t.Errorf("Was not expecting an error")
- }
- err = (&g).Scan(v)
- if err != nil {
- t.Errorf("Was not expecting an error")
- }
- if string(g) != "Hello, world" {
- t.Errorf("Was expecting the string we sent in (Hello World), got %s", string(g))
- }
-}
-
-func TestJSONText(t *testing.T) {
- j := JSONText(`{"foo": 1, "bar": 2}`)
- v, err := j.Value()
- if err != nil {
- t.Errorf("Was not expecting an error")
- }
- err = (&j).Scan(v)
- if err != nil {
- t.Errorf("Was not expecting an error")
- }
- m := map[string]interface{}{}
- j.Unmarshal(&m)
-
- if m["foo"].(float64) != 1 || m["bar"].(float64) != 2 {
- t.Errorf("Expected valid json but got some garbage instead? %#v", m)
- }
-
- j = JSONText(`{"foo": 1, invalid, false}`)
- v, err = j.Value()
- if err == nil {
- t.Errorf("Was expecting invalid json to fail!")
- }
-
- j = JSONText("")
- v, err = j.Value()
- if err != nil {
- t.Errorf("Was not expecting an error")
- }
-
- err = (&j).Scan(v)
- if err != nil {
- t.Errorf("Was not expecting an error")
- }
-
- j = JSONText(nil)
- v, err = j.Value()
- if err != nil {
- t.Errorf("Was not expecting an error")
- }
-
- err = (&j).Scan(v)
- if err != nil {
- t.Errorf("Was not expecting an error")
- }
-}
-
-func TestNullJSONText(t *testing.T) {
- j := NullJSONText{}
- err := j.Scan(`{"foo": 1, "bar": 2}`)
- if err != nil {
- t.Errorf("Was not expecting an error")
- }
- v, err := j.Value()
- if err != nil {
- t.Errorf("Was not expecting an error")
- }
- err = (&j).Scan(v)
- if err != nil {
- t.Errorf("Was not expecting an error")
- }
- m := map[string]interface{}{}
- j.Unmarshal(&m)
-
- if m["foo"].(float64) != 1 || m["bar"].(float64) != 2 {
- t.Errorf("Expected valid json but got some garbage instead? %#v", m)
- }
-
- j = NullJSONText{}
- err = j.Scan(nil)
- if err != nil {
- t.Errorf("Was not expecting an error")
- }
- if j.Valid != false {
- t.Errorf("Expected valid to be false, but got true")
- }
-}
-
-func TestBitBool(t *testing.T) {
- // Test true value
- var b BitBool = true
-
- v, err := b.Value()
- if err != nil {
- t.Errorf("Cannot return error")
- }
- err = (&b).Scan(v)
- if err != nil {
- t.Errorf("Was not expecting an error")
- }
- if !b {
- t.Errorf("Was expecting the bool we sent in (true), got %v", b)
- }
-
- // Test false value
- b = false
-
- v, err = b.Value()
- if err != nil {
- t.Errorf("Cannot return error")
- }
- err = (&b).Scan(v)
- if err != nil {
- t.Errorf("Was not expecting an error")
- }
- if b {
- t.Errorf("Was expecting the bool we sent in (false), got %v", b)
- }
-}