null

package
v0.0.0-...-0a8238e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package null contains types which can be NULL in some storage engines.

The aim is to import database/sql to avoid the dependency on SQL. Null values can occur everywhere hence we want to keep the deps minimal.

Index

Constants

This section is empty.

Variables

View Source
var (
	JSONMarshalFn   func(v interface{}) ([]byte, error)
	JSONUnMarshalFn func(data []byte, v interface{}) error
)

JSONMarshalFn and JSONUnMarshalFn functions which must be set if you decide to use JSON. Otherwise it panics. In your package write somewhere:

null.JSONMarshalFn = json.Marshal
null.JSONUnMarshalFn = json.UnMarshal

Functions

This section is empty.

Types

type Bool

type Bool struct {
	Bool  bool
	Valid bool // Valid is true if Bool is not NULL
}

Bool is a nullable bool. It does not consider false values to be null. It will decode to null, not false, if null. Bool implements interface Argument.

func MakeBool

func MakeBool(b bool) Bool

MakeBool creates a new Bool. Implements interface Argument.

func MakeBoolFromByte

func MakeBoolFromByte(data []byte) (nv Bool, err error)

MakeBoolFromByte makes a new Bool from a (text) byte slice.

func (Bool) Append

func (a Bool) Append(args []interface{}) []interface{}

Append appends the value or its nil type to the interface slice.

func (Bool) GoString

func (a Bool) GoString() string

GoString prints an optimized Go representation.

func (*Bool) GobDecode

func (a *Bool) GobDecode(data []byte) error

GobDecode implements the gob.GobDecoder interface for gob serialization.

func (Bool) GobEncode

func (a Bool) GobEncode() ([]byte, error)

GobEncode implements the gob.GobEncoder interface for gob serialization.

func (Bool) IsZero

func (a Bool) IsZero() bool

IsZero returns true for invalid Bools, for future omitempty support (Go 1.4?) A non-null Bool with a 0 value will not be considered zero.

func (Bool) Marshal

func (a Bool) Marshal() ([]byte, error)

Marshal binary encoder for protocol buffers. Implements proto.Marshaler.

func (Bool) MarshalBinary

func (a Bool) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (Bool) MarshalJSON

func (a Bool) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It will encode null if this Bool is null.

func (Bool) MarshalText

func (a Bool) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It will encode a blank string if this Bool is null.

func (Bool) MarshalTo

func (a Bool) MarshalTo(data []byte) (n int, err error)

MarshalTo binary encoder for protocol buffers which writes into data.

func (Bool) Ptr

func (a Bool) Ptr() *bool

Ptr returns a pointer to this Bool's value, or a nil pointer if this Bool is null.

func (*Bool) Scan

func (a *Bool) Scan(value interface{}) (err error)

Scan implements the Scanner interface.

func (Bool) SetNull

func (a Bool) SetNull() Bool

SetNull sets the value to Go's default value and Valid to false.

func (Bool) SetValid

func (a Bool) SetValid(v bool) Bool

SetValid changes this Bool's value and also sets it to be non-null.

func (Bool) Size

func (a Bool) Size() (s int)

Size returns the size of the underlying type. If not valid, the size will be 0. Implements proto.Sizer.

func (Bool) String

func (a Bool) String() string

GoString prints an optimized Go representation.

func (*Bool) Unmarshal

func (a *Bool) Unmarshal(data []byte) error

Unmarshal binary decoder for protocol buffers. Implements proto.Unmarshaler.

func (*Bool) UnmarshalBinary

func (a *Bool) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*Bool) UnmarshalJSON

func (a *Bool) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will not be considered a null Bool. It also supports unmarshalling a sql.Bool.

func (*Bool) UnmarshalText

func (a *Bool) UnmarshalText(text []byte) (err error)

UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Bool if the input is a blank or not an integer. It will return an error if the input is not an integer, blank, or "null".

func (Bool) Value

func (a Bool) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Bool) WriteTo

func (a Bool) WriteTo(d Dialecter, w *bytes.Buffer) (err error)

WriteTo uses a special dialect to encode the value and write it into w. w cannot be replaced by io.Writer and shall not be replaced by an interface because of inlining features of the compiler.

type Decimal

type Decimal struct {
	PrecisionStr string // Not empty if to large for an uint64
	Precision    uint64 // The value itself, always set if it fits into an uint64
	Scale        int32  // Number of digits after the dot
	Negative     bool
	Valid        bool
	// Quote if true JSON marshaling will quote the returned number and creates
	// a string. JavaScript floats are only 53 bits.
	Quote bool
	// contains filtered or unexported fields
}

Decimal defines a container type for any MySQL/MariaDB decimal/numeric/float/double data type and their representation in Go. It can store arbitrary large values. Decimal does not perform any kind of calculations. Helpful packages for arbitrary precision calculations are github.com/ericlagergren/decimal or gopkg.in/inf.v0 or github.com/shopspring/decimal or a future new Go type. https://dev.mysql.com/doc/refman/5.7/en/precision-math-decimal-characteristics.html https://dev.mysql.com/doc/refman/5.7/en/floating-point-types.html

func MakeDecimalBytes

func MakeDecimalBytes(b []byte) (d Decimal, err error)

MakeDecimalBytes parses b to create a new Decimal. b must contain ASCII numbers. If b contains null/NULL the returned object represents that value. This function can be used for big.Int.Bytes() or similar implementations. Parses only numbers as stored in MySQL/MariaDB decimal/double column format, e.g. -47.11.

func MakeDecimalFloat64

func MakeDecimalFloat64(value float64) (d Decimal, err error)

MakeDecimalFloat64 converts a float64 to Decimal.

Example:

MakeDecimalFloat64(123.45678901234567).String()  // output: "123.45678901234567"
MakeDecimalFloat64(123.456789012345678).String() // output: "123.45678901234568"
MakeDecimalFloat64(.00000000000000001).String() // output: "0.00000000000000001"

func MakeDecimalInt64

func MakeDecimalInt64(value int64, scale int32) Decimal

MakeDecimalInt64 converts an int64 with the scale to a Decimal.

func MustMakeDecimalBytes

func MustMakeDecimalBytes(data []byte) Decimal

MustMakeDecimalBytes same behaviour as MakeDecimalBytes but panics on error.

func (Decimal) Equal

func (d Decimal) Equal(d2 Decimal) bool

Equal compares another Decimal object for equality. Equality can only succeed when both `Valid` fields are true.

func (Decimal) Float64

func (d Decimal) Float64() (value float64)

Float64 converts the precision and the scale to a float64 value including the usual float behaviour. Overflow will result in an undefined float64.

func (Decimal) GoString

func (d Decimal) GoString() string

GoString returns an optimized version of the Go representation of Decimal.

func (*Decimal) GobDecode

func (d *Decimal) GobDecode(data []byte) error

GobDecode implements the gob.GobDecoder interface for gob serialization.

func (Decimal) GobEncode

func (d Decimal) GobEncode() ([]byte, error)

GobEncode implements the gob.GobEncoder interface for gob serialization.

func (Decimal) Int64

func (d Decimal) Int64() (value int64, scale int32)

Int64 converts the underlying uint64 to an int64. Very useful for creating a new 3rd party package type/object. If the Precision field overflows math.MaxInt64 the return values are 0,0. If you want to aovid this use the String function and create the 3rd party type via the string.

func (Decimal) Marshal

func (d Decimal) Marshal() ([]byte, error)

Marshal binary encoder for protocol buffers. Implements proto.Marshaler.

func (Decimal) MarshalBinary

func (d Decimal) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (Decimal) MarshalJSON

func (d Decimal) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Decimal) MarshalText

func (d Decimal) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface for XML serialization. Does not support quoting. An invalid type returns an empty string.

func (Decimal) MarshalTo

func (d Decimal) MarshalTo(data []byte) (n int, err error)

MarshalTo binary encoder for protocol buffers which writes into [14]data.

func (*Decimal) Scan

func (d *Decimal) Scan(value interface{}) (err error)

Scan implements the Scanner interface. Approx. >3x times faster than database/sql.convertAssign.

func (Decimal) SetNull

func (d Decimal) SetNull() Decimal

SetNull sets the value to Go's default value and Valid to false.

func (Decimal) Size

func (d Decimal) Size() (s int)

Size returns the size of the underlying type. If not valid, the size will be 0. Implements proto.Sizer.

func (Decimal) String

func (d Decimal) String() string

String returns the string representation of the fixed with decimal. Returns the word `NULL` if the current value is not valid, for now.

func (*Decimal) Unmarshal

func (d *Decimal) Unmarshal(data []byte) error

Unmarshal binary decoder for protocol buffers. Implements proto.Unmarshaler.

func (*Decimal) UnmarshalBinary

func (d *Decimal) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface. As a string representation is already used when encoding to text, this method stores that string as []byte

func (*Decimal) UnmarshalJSON

func (d *Decimal) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Decimal) UnmarshalText

func (d *Decimal) UnmarshalText(text []byte) (err error)

UnmarshalText implements the encoding.TextUnmarshaler interface for XML deserialization.

func (Decimal) Value

func (d Decimal) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database serialization. It stores a string in driver.Value.

type Dialecter

type Dialecter interface {
	EscapeIdent(w *bytes.Buffer, ident string)
	EscapeBool(w *bytes.Buffer, b bool)
	EscapeString(w *bytes.Buffer, s string)
	EscapeTime(w *bytes.Buffer, t time.Time)
	EscapeBinary(w *bytes.Buffer, b []byte)
}

Dialecter at an interface that wraps the diverse properties of individual SQL drivers.

type Float64

type Float64 struct {
	Float64 float64
	Valid   bool // Valid is true if Float64 is not NULL
}

Float64 is a nullable float64. It does not consider zero values to be null. It will decode to null, not zero, if null.

func MakeFloat64

func MakeFloat64(f float64) Float64

MakeFloat64 creates a new Float64. Setting the second optional argument to false, the string will not be valid anymore, hence NULL. Float64 implements interface Argument.

func MakeFloat64FromByte

func MakeFloat64FromByte(data []byte) (nv Float64, err error)

MakeFloat64FromByte makes a new Float64 from a (text) byte slice.

func (Float64) Append

func (a Float64) Append(args []interface{}) []interface{}

Append appends the value or its nil type to the interface slice.

func (Float64) GoString

func (a Float64) GoString() string

GoString prints an optimized Go representation.

func (*Float64) GobDecode

func (a *Float64) GobDecode(data []byte) error

GobDecode implements the gob.GobDecoder interface for gob serialization.

func (Float64) GobEncode

func (a Float64) GobEncode() ([]byte, error)

GobEncode implements the gob.GobEncoder interface for gob serialization.

func (Float64) IsZero

func (a Float64) IsZero() bool

IsZero returns true for invalid Float64s, for future omitempty support (Go 1.4?) A non-null Float64 with a 0 value will not be considered zero.

func (Float64) Marshal

func (a Float64) Marshal() ([]byte, error)

Marshal binary encoder for protocol buffers. Implements proto.Marshaler.

func (Float64) MarshalBinary

func (a Float64) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (Float64) MarshalJSON

func (a Float64) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It will encode null if this Float64 is null.

func (Float64) MarshalText

func (a Float64) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It will encode a blank string if this Float64 is null.

func (Float64) MarshalTo

func (a Float64) MarshalTo(data []byte) (n int, err error)

MarshalTo binary encoder for protocol buffers which writes into data.

func (Float64) Ptr

func (a Float64) Ptr() *float64

Ptr returns a pointer to this Float64's value, or a nil pointer if this Float64 is null.

func (*Float64) Scan

func (a *Float64) Scan(value interface{}) (err error)

Scan implements the Scanner interface. Approx. >3x times faster than database/sql.convertAssign.

func (Float64) SetNull

func (a Float64) SetNull() Float64

SetNull sets the value to Go's default value and Valid to false.

func (Float64) SetValid

func (a Float64) SetValid(n float64) Float64

SetValid changes this Float64's value and also sets it to be non-null.

func (Float64) Size

func (a Float64) Size() (s int)

Size returns the size of the underlying type. If not valid, the size will be 0. Implements proto.Sizer.

func (Float64) String

func (a Float64) String() string

String returns the string representation of the float or null.

func (*Float64) Unmarshal

func (a *Float64) Unmarshal(data []byte) error

Unmarshal binary decoder for protocol buffers. Implements proto.Unmarshaler.

func (*Float64) UnmarshalBinary

func (a *Float64) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*Float64) UnmarshalJSON

func (a *Float64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will not be considered a null Float64. It also supports unmarshalling a sql.Float64.

func (*Float64) UnmarshalText

func (a *Float64) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Float64 if the input is a blank or not an integer. It will return an error if the input is not an integer, blank, or "null".

func (Float64) Value

func (a Float64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Float64) WriteTo

func (a Float64) WriteTo(_ Dialecter, w *bytes.Buffer) (err error)

WriteTo uses a special dialect to encode the value and write it into w. w cannot be replaced by io.Writer and shall not be replaced by an interface because of inlining features of the compiler.

type Int64

type Int64 struct {
	Int64 int64
	Valid bool // Valid is true if Int64 is not NULL
}

Int64 is a nullable int64. It does not consider zero values to be null. It will decode to null, not zero, if null. Int64 implements interface Argument.

func MakeInt64

func MakeInt64(i int64) Int64

MakeInt64 creates a new Int64. Setting the second optional argument to false, the string will not be valid anymore, hence NULL. Int64 implements interface Argument.

func MakeInt64FromByte

func MakeInt64FromByte(data []byte) (nv Int64, err error)

MakeInt64FromByte makes a new Int64 from a (text) byte slice.

func (Int64) Append

func (a Int64) Append(args []interface{}) []interface{}

Append appends the value or its nil type to the interface slice.

func (Int64) GoString

func (a Int64) GoString() string

GoString prints an optimized Go representation. Takes are of backticks.

func (*Int64) GobDecode

func (a *Int64) GobDecode(data []byte) error

GobDecode implements the gob.GobDecoder interface for gob serialization.

func (Int64) GobEncode

func (a Int64) GobEncode() ([]byte, error)

GobEncode implements the gob.GobEncoder interface for gob serialization.

func (Int64) IsZero

func (a Int64) IsZero() bool

IsZero returns true for invalid Int64's, for future omitempty support (Go 1.4?) A non-null Int64 with a 0 value will not be considered zero.

func (Int64) Marshal

func (a Int64) Marshal() ([]byte, error)

Marshal binary encoder for protocol buffers. Implements proto.Marshaler.

func (Int64) MarshalBinary

func (a Int64) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (Int64) MarshalJSON

func (a Int64) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It will encode null if this Int64 is null.

func (Int64) MarshalText

func (a Int64) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It will encode a blank string if this Int64 is null.

func (Int64) MarshalTo

func (a Int64) MarshalTo(data []byte) (n int, err error)

MarshalTo binary encoder for protocol buffers which writes into data.

func (Int64) Ptr

func (a Int64) Ptr() *int64

Ptr returns a pointer to this Int64's value, or a nil pointer if this Int64 is null.

func (*Int64) Scan

func (a *Int64) Scan(value interface{}) (err error)

Scan implements the Scanner interface. Approx. >3x times faster than database/sql.convertAssign.

func (Int64) SetNull

func (a Int64) SetNull() Int64

SetNull sets the value to Go's default value and Valid to false.

func (Int64) SetValid

func (a Int64) SetValid(n int64) Int64

SetValid changes this Int64's value and also sets it to be non-null.

func (Int64) Size

func (a Int64) Size() (s int)

Size returns the size of the underlying type. If not valid, the size will be 0. Implements proto.Sizer.

func (Int64) String

func (a Int64) String() string

String returns the string representation of the int or null.

func (*Int64) Unmarshal

func (a *Int64) Unmarshal(data []byte) error

Unmarshal binary decoder for protocol buffers. Implements proto.Unmarshaler.

func (*Int64) UnmarshalBinary

func (a *Int64) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*Int64) UnmarshalJSON

func (a *Int64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will not be considered a null Int64. It also supports unmarshalling a sql.Int64.

func (*Int64) UnmarshalText

func (a *Int64) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Int64 if the input is a blank or not an integer. It will return an error if the input is not an integer, blank, or sqlStrNullLC.

func (Int64) Value

func (a Int64) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

func (Int64) WriteTo

func (a Int64) WriteTo(_ Dialecter, w *bytes.Buffer) (err error)

WriteTo uses a special dialect to encode the value and write it into w. w cannot be replaced by io.Writer and shall not be replaced by an interface because of inlining features of the compiler.

type String

type String struct {
	String string
	Valid  bool // Valid is true if String is not NULL
}

String is a nullable string. It supports SQL and JSON serialization. It will marshal to null if null. Blank string input will be considered null. String implements interface Argument.

func MakeString

func MakeString(s string) String

MakeString creates a new String. Setting the second optional argument to false, the string will not be valid anymore, hence NULL. String implements interface Argument.

func (String) Append

func (a String) Append(args []interface{}) []interface{}

Append appends the value or its nil type to the interface slice.

func (String) GoString

func (a String) GoString() string

GoString prints an optimized Go representation. Takes are of backticks. Looses the information of the private operator. That might get fixed.

func (*String) GobDecode

func (a *String) GobDecode(data []byte) error

GobDecode implements the gob.GobDecoder interface for gob serialization.

func (String) GobEncode

func (a String) GobEncode() ([]byte, error)

GobEncode implements the gob.GobEncoder interface for gob serialization.

func (String) IsZero

func (a String) IsZero() bool

IsZero returns true for null strings, for potential future omitempty support.

func (String) Marshal

func (a String) Marshal() ([]byte, error)

Marshal binary encoder for protocol buffers. Implements proto.Marshaler.

func (String) MarshalBinary

func (a String) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (String) MarshalJSON

func (a String) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It will encode null if this String is null.

func (String) MarshalText

func (a String) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It will encode a blank string when this String is null.

func (String) MarshalTo

func (a String) MarshalTo(data []byte) (n int, err error)

MarshalTo binary encoder for protocol buffers which writes into data.

func (String) Ptr

func (a String) Ptr() *string

Ptr returns a pointer to this String's value, or a nil pointer if this String is null.

func (*String) Scan

func (a *String) Scan(value interface{}) (err error)

Scan implements the Scanner interface. Approx. >2x times faster than database/sql.convertAssign.

func (String) SetNull

func (a String) SetNull() String

SetNull sets the value to Go's default value and Valid to false.

func (String) SetValid

func (a String) SetValid(v string) String

SetValid changes this String's value and also sets it to be non-null.

func (String) Size

func (a String) Size() (s int)

Size returns the size of the underlying type. If not valid, the size will be 0. Implements proto.Sizer.

func (*String) Unmarshal

func (a *String) Unmarshal(data []byte) error

Unmarshal binary decoder for protocol buffers. Implements proto.Unmarshaler.

func (*String) UnmarshalBinary

func (a *String) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*String) UnmarshalJSON

func (a *String) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. It supports string and null input. Blank string input does not produce a null String. It also supports unmarshalling a sql.String.

func (*String) UnmarshalText

func (a *String) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null String if the input is a blank string.

func (String) Value

func (a String) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (String) WriteTo

func (a String) WriteTo(d Dialecter, w *bytes.Buffer) (err error)

WriteTo uses a special dialect to encode the value and write it into w. w cannot be replaced by io.Writer and shall not be replaced by an interface because of inlining features of the compiler.

type Time

type Time struct {
	Time  time.Time
	Valid bool // Valid is true if Time is not NULL
}

Time represents a time.Time that may be NULL. Time implements the Scanner interface so it can be used as a scan destination:

var nt Time
err := db.QueryRow("SELECT time FROM foo WHERE id=?", id).Scan(&nt)
...
if nt.Valid {
   // use nt.Time
} else {
   // NULL value
}

This Time implementation is not driver-specific

func MakeTime

func MakeTime(t time.Time) Time

MakeTime creates a new Time. Setting the second optional argument to false, the string will not be valid anymore, hence NULL. Time implements interface Argument.

func ParseDateTime

func ParseDateTime(str string, loc *time.Location) (t Time, err error)

ParseDateTime parses a string into a Time type. Empty string is considered NULL.

func (Time) Append

func (nt Time) Append(args []interface{}) []interface{}

Append appends the value or its nil type to the interface slice.

func (Time) GoString

func (nt Time) GoString() string

GoString prints an optimized Go representation.

func (*Time) GobDecode

func (nt *Time) GobDecode(data []byte) error

GobDecode implements the gob.GobDecoder interface for gob serialization.

func (Time) GobEncode

func (nt Time) GobEncode() ([]byte, error)

GobEncode implements the gob.GobEncoder interface for gob serialization.

func (Time) Marshal

func (nt Time) Marshal() ([]byte, error)

Marshal binary encoder for protocol buffers. Implements proto.Marshaler.

func (Time) MarshalBinary

func (nt Time) MarshalBinary() (data []byte, err error)

MarshalBinary transforms the time type into a byte slice.

func (Time) MarshalJSON

func (nt Time) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It will encode null if this time is null.

func (Time) MarshalText

func (nt Time) MarshalText() ([]byte, error)

MarshalText transforms the time type into a byte slice.

func (Time) MarshalTo

func (nt Time) MarshalTo(data []byte) (int, error)

MarshalTo binary encoder for protocol buffers which writes into data.

func (Time) Ptr

func (nt Time) Ptr() *time.Time

Ptr returns a pointer to this Time's value, or a nil pointer if this Time is null.

func (*Time) Scan

func (nt *Time) Scan(value interface{}) (err error)

Scan implements the Scanner interface. The value type must be time.Time or string / []byte (formatted time-string), otherwise Scan fails.

func (Time) SetNull

func (nt Time) SetNull() Time

SetNull sets the value to Go's default value and Valid to false.

func (Time) SetValid

func (nt Time) SetValid(v time.Time) Time

SetValid changes this Time's value and sets it to be non-null.

func (Time) Size

func (nt Time) Size() (n int)

Size returns the size of the underlying type. If not valid, the size will be 0. Implements proto.Sizer.

func (Time) String

func (nt Time) String() string

String returns the string representation of the time or null.

func (*Time) Unmarshal

func (nt *Time) Unmarshal(data []byte) error

Unmarshal binary decoder for protocol buffers. Implements proto.Unmarshaler.

func (*Time) UnmarshalBinary

func (nt *Time) UnmarshalBinary(data []byte) error

UnmarshalBinary parses the byte slice to create a time type.

func (*Time) UnmarshalJSON

func (nt *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. It supports string, object (e.g. pq.Time and friends) and null input.

func (*Time) UnmarshalText

func (nt *Time) UnmarshalText(text []byte) error

UnmarshalText parses the byte slice to create a time type.

func (Time) Value

func (nt Time) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

func (Time) WriteTo

func (nt Time) WriteTo(d Dialecter, w *bytes.Buffer) (err error)

WriteTo uses a special dialect to encode the value and write it into w. w cannot be replaced by io.Writer and shall not be replaced by an interface because of inlining features of the compiler.

type Uint64

type Uint64 struct {
	Uint64 uint64
	Valid  bool // Valid is true if Uint64 is not NULL
}

Uint64 is a nullable int64. It does not consider zero values to be null. It will decode to null, not zero, if null. Uint64 implements interface Argument.

func MakeUint64

func MakeUint64(i uint64) Uint64

MakeUint64 creates a new Uint64. Setting the second optional argument to false, the string will not be valid anymore, hence NULL. Uint64 implements interface Argument.

func MakeUint64FromByte

func MakeUint64FromByte(data []byte) (nv Uint64, err error)

MakeUint64FromByte makes a new Uint64 from a (text) byte slice.

func (Uint64) Append

func (a Uint64) Append(args []interface{}) []interface{}

Append appends the value or its nil type to the interface slice.

func (Uint64) GoString

func (a Uint64) GoString() string

GoString prints an optimized Go representation. Takes are of backticks.

func (*Uint64) GobDecode

func (a *Uint64) GobDecode(data []byte) error

GobDecode implements the gob.GobDecoder interface for gob serialization.

func (Uint64) GobEncode

func (a Uint64) GobEncode() ([]byte, error)

GobEncode implements the gob.GobEncoder interface for gob serialization.

func (Uint64) IsZero

func (a Uint64) IsZero() bool

IsZero returns true for invalid Uint64's, for future omitempty support (Go 1.4?) A non-null Uint64 with a 0 value will not be considered zero.

func (Uint64) Marshal

func (a Uint64) Marshal() ([]byte, error)

Marshal binary encoder for protocol buffers. Implements proto.Marshaler.

func (Uint64) MarshalBinary

func (a Uint64) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (Uint64) MarshalJSON

func (a Uint64) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It will encode null if this Uint64 is null.

func (Uint64) MarshalText

func (a Uint64) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It will encode a blank string if this Uint64 is null.

func (Uint64) MarshalTo

func (a Uint64) MarshalTo(data []byte) (n int, err error)

MarshalTo binary encoder for protocol buffers which writes into data.

func (Uint64) Ptr

func (a Uint64) Ptr() *uint64

Ptr returns a pointer to this Uint64's value, or a nil pointer if this Uint64 is null.

func (*Uint64) Scan

func (a *Uint64) Scan(value interface{}) (err error)

Scan implements the Scanner interface. Approx. >3x times faster than database/sql.convertAssign

func (Uint64) SetNull

func (a Uint64) SetNull() Uint64

SetNull sets the value to Go's default value and Valid to false.

func (Uint64) SetValid

func (a Uint64) SetValid(n uint64) Uint64

SetValid changes this Uint64's value and also sets it to be non-null.

func (Uint64) Size

func (a Uint64) Size() (s int)

Size returns the size of the underlying type. If not valid, the size will be 0. Implements proto.Sizer.

func (Uint64) String

func (a Uint64) String() string

String returns the string representation of the int or null.

func (*Uint64) Unmarshal

func (a *Uint64) Unmarshal(data []byte) error

Unmarshal binary decoder for protocol buffers. Implements proto.Unmarshaler.

func (*Uint64) UnmarshalBinary

func (a *Uint64) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*Uint64) UnmarshalJSON

func (a *Uint64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will not be considered a null Uint64. It also supports unmarshalling a sql.Uint64.

func (*Uint64) UnmarshalText

func (a *Uint64) UnmarshalText(text []byte) (err error)

UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Uint64 if the input is a blank or not an integer. It will return an error if the input is not an integer, blank, or sqlStrNullLC.

func (Uint64) Value

func (a Uint64) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

func (Uint64) WriteTo

func (a Uint64) WriteTo(_ Dialecter, w *bytes.Buffer) (err error)

WriteTo uses a special dialect to encode the value and write it into w. w cannot be replaced by io.Writer and shall not be replaced by an interface because of inlining features of the compiler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL