sqltypes

package
v0.0.0-...-3370840 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2017 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sqltypes implements interfaces and types that represent SQL values.

Index

Constants

This section is empty.

Variables

View Source
var (
	NULL       = Value{}
	DONTESCAPE = byte(255)
)
View Source
var SqlDecodeMap [256]byte

SqlDecodeMap is the reverse of SqlEncodeMap

View Source
var SqlEncodeMap [256]byte

SqlEncodeMap specifies how to escape binary data with '\'. Complies to http://dev.mysql.com/doc/refman/5.1/en/string-syntax.html

Functions

func ToStrings

func ToStrings(in []CIString) []string

ToStrings converts a []CIString to a case-preserved []string.

Types

type BinWriter

type BinWriter interface {
	Write([]byte) (int, error)
	WriteByte(byte) error
}

BinWriter interface is used for encoding values. Types like bytes.Buffer conform to this interface. We expect the writer objects to be in-memory buffers. So, we don't expect the write operations to fail.

type CIString

type CIString struct {
	// contains filtered or unexported fields
}

CIString is an immutable case-insensitive string. It precomputes and stores the lower case version of the string internally. This increases the initial memory cost of the object but saves the CPU (and memory) cost of lowercasing as needed. This should generally trade off favorably because there are many situations where comparisons are performed in a loop against the same object.

func New

func New(str string) CIString

New creates a new CIString.

func (CIString) Equal

func (s CIString) Equal(in CIString) bool

Equal performs a case-insensitive compare. For comparing in a loop, it's beneficial to build a CIString outside the loop and using it to compare with other CIString variables inside the loop.

func (CIString) EqualString

func (s CIString) EqualString(in string) bool

EqualString performs a case-insensitive compare with str. If the input is already lower-cased, it's more efficient to check if s.Lowered()==in.

func (CIString) Lowered

func (s CIString) Lowered() string

Lowered returns the lower-case value of the string. This function should generally be used only for optimizing comparisons.

func (CIString) MarshalJSON

func (s CIString) MarshalJSON() ([]byte, error)

MarshalJSON marshals into JSON.

func (CIString) Original

func (s CIString) Original() string

Original returns the case-preserved value of the string.

func (CIString) String

func (s CIString) String() string

func (*CIString) UnmarshalJSON

func (s *CIString) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals from JSON.

type Fractional

type Fractional []byte

Fractional represents fractional types like float and decimal It's functionally equivalent to Numeric other than how it's constructed

type InnerValue

type InnerValue interface {
	// contains filtered or unexported methods
}

InnerValue defines methods that need to be supported by all non-null value types.

type Numeric

type Numeric []byte

Numeric represents non-fractional SQL number.

func (Numeric) MarshalJSON

func (n Numeric) MarshalJSON() ([]byte, error)

type String

type String []byte

String represents any SQL type that needs to be represented using quotes.

type Value

type Value struct {
	Inner InnerValue
}

Value can store any SQL value. NULL is stored as nil.

func BuildNumeric

func BuildNumeric(val string) (n Value, err error)

BuildNumeric builds a Numeric type that represents any whole number. It normalizes the representation to ensure 1:1 mapping between the number and its representation.

func BuildValue

func BuildValue(goval interface{}) (v Value, err error)

func MakeFractional

func MakeFractional(b []byte) Value

MakeFractional makes a Fractional value from a []byte without validation.

func MakeNumeric

func MakeNumeric(b []byte) Value

MakeNumeric makes a Numeric from a []byte without validation.

func MakeString

func MakeString(b []byte) Value

MakeString makes a String value from a []byte.

func (Value) EncodeAscii

func (v Value) EncodeAscii(b BinWriter)

EncodeAscii encodes the value using 7-bit clean ascii bytes.

func (Value) EncodeSql

func (v Value) EncodeSql(b BinWriter)

EncodeSql encodes the value into an SQL statement. Can be binary.

func (Value) IsFractional

func (v Value) IsFractional() (ok bool)

func (Value) IsNull

func (v Value) IsNull() bool

func (Value) IsNumeric

func (v Value) IsNumeric() (ok bool)

func (Value) IsString

func (v Value) IsString() (ok bool)

func (Value) MarshalJSON

func (v Value) MarshalJSON() ([]byte, error)

MarshalJSON should only be used for testing. It's not a complete implementation.

func (Value) ParseInt64

func (v Value) ParseInt64() (val int64, err error)

ParseInt64 will parse a Numeric value into an int64

func (Value) ParseUint64

func (v Value) ParseUint64() (val uint64, err error)

ParseUint64 will parse a Numeric value into a uint64

func (Value) Raw

func (v Value) Raw() []byte

Raw returns the raw bytes. All types are currently implemented as []byte.

func (Value) String

func (v Value) String() string

String returns the raw value as a string

func (*Value) UnmarshalJSON

func (v *Value) UnmarshalJSON(b []byte) error

UnmarshalJSON should only be used for testing. It's not a complete implementation.

Jump to

Keyboard shortcuts

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