sqltypes

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package sqltypes implements interfaces and types that represent SQL values.

Index

Constants

Vitess data types. These are idiomatically named synonyms for the querypb.Type values.

Variables

View Source
var (
	// NULL represents the NULL value.
	NULL = Value{}
	// DontEscape tells you if a character should not be escaped.
	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 EventTokenMinimum

func EventTokenMinimum(ev1, ev2 *querypb.EventToken) *querypb.EventToken

EventTokenMinimum returns an event token that is guaranteed to happen before both provided EventToken objects. Note it doesn't parse the position, but rather only uses the timestamp. This is meant to be used for EventToken objects coming from different source shard.

func IsBinary

func IsBinary(t querypb.Type) bool

IsBinary returns true if querypb.Type is a binary.

func IsFloat

func IsFloat(t querypb.Type) bool

IsFloat returns true is querypb.Type is a floating point.

func IsIntegral

func IsIntegral(t querypb.Type) bool

IsIntegral returns true if querypb.Type is an integral (signed/unsigned) that can be represented using up to 64 binary bits.

func IsQuoted

func IsQuoted(t querypb.Type) bool

IsQuoted returns true if querypb.Type is a quoted text or binary.

func IsSigned

func IsSigned(t querypb.Type) bool

IsSigned returns true if querypb.Type is a signed integral.

func IsText

func IsText(t querypb.Type) bool

IsText returns true if querypb.Type is a text.

func IsUnsigned

func IsUnsigned(t querypb.Type) bool

IsUnsigned returns true if querypb.Type is an unsigned integral. Caution: this is not the same as !IsSigned.

func MySQLToType

func MySQLToType(mysqlType, flags int64) (typ querypb.Type, err error)

MySQLToType computes the vitess type from mysql type and flags.

func RowToProto3

func RowToProto3(row []Value) *querypb.Row

RowToProto3 converts []Value to proto3.

func RowsToProto3

func RowsToProto3(rows [][]Value) []*querypb.Row

RowsToProto3 converts [][]Value to proto3.

func TypeToMySQL

func TypeToMySQL(typ querypb.Type) (mysqlType, flags int64)

TypeToMySQL returns the equivalent mysql type and flag for a vitess type.

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 Value

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

Value can store any SQL value. If the value represents an integral type, the bytes are always stored as a cannonical representation that matches how MySQL returns such values.

func BuildConverted

func BuildConverted(typ querypb.Type, goval interface{}) (v Value, err error)

BuildConverted is like BuildValue except that it tries to convert a string or []byte to an integral if the target type is an integral. We don't perform other implicit conversions because they're unsafe.

func BuildIntegral

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

BuildIntegral builds an integral type from a string representaion. The type will be Int64 or Uint64. Int64 will be preferred where possible.

func BuildValue

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

BuildValue builds a value from any go type. sqltype.Value is also allowed.

func MakeString

func MakeString(val []byte) Value

MakeString makes a VarBinary Value.

func MakeTrusted

func MakeTrusted(typ querypb.Type, val []byte) Value

MakeTrusted makes a new Value based on the type. If the value is an integral, then val must be in its cannonical form. This function should only be used if you know the value and type conform to the rules. Every place this function is called, a comment is needed that explains why it's justified. Functions within this package are exempt.

func ValueFromBytes

func ValueFromBytes(typ querypb.Type, val []byte) (v Value, err error)

ValueFromBytes builds a Value using typ and val. It ensures that val matches the requested type. If type is an integral it's converted to a cannonical form. Otherwise, the original representation is preserved.

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) IsBinary

func (v Value) IsBinary() bool

IsBinary returns true if Value is binary.

func (Value) IsFloat

func (v Value) IsFloat() bool

IsFloat returns true if Value is a float.

func (Value) IsIntegral

func (v Value) IsIntegral() bool

IsIntegral returns true if Value is an integral.

func (Value) IsNull

func (v Value) IsNull() bool

IsNull returns true if Value is null.

func (Value) IsQuoted

func (v Value) IsQuoted() bool

IsQuoted returns true if Value must be SQL-quoted.

func (Value) IsSigned

func (v Value) IsSigned() bool

IsSigned returns true if Value is a signed integral.

func (Value) IsText

func (v Value) IsText() bool

IsText returns true if Value is a collatable text.

func (Value) IsUnsigned

func (v Value) IsUnsigned() bool

IsUnsigned returns true if Value is an unsigned integral.

func (Value) Len

func (v Value) Len() int

Len returns the length.

func (Value) MarshalJSON

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

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

func (Value) ParseFloat64

func (v Value) ParseFloat64() (val float64, err error)

ParseFloat64 will parse a Value into an float64. It does not check the type.

func (Value) ParseInt64

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

ParseInt64 will parse a Value into an int64. It does not check the type.

func (Value) ParseUint64

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

ParseUint64 will parse a Value into a uint64. It does not check the type.

func (Value) Raw

func (v Value) Raw() []byte

Raw returns the raw bytes. All types are currently implemented as []byte. You should avoid using this function. If you do, you should treat the bytes as read-only.

func (Value) String

func (v Value) String() string

String returns the raw value as a string.

func (Value) ToNative

func (v Value) ToNative() interface{}

ToNative converts Value to a native go type. This does not work for sqltypes.Tuple. The function panics if there are inconsistencies.

func (Value) ToProtoValue

func (v Value) ToProtoValue() *querypb.Value

ToProtoValue converts Value to a querypb.Value.

func (Value) Type

func (v Value) Type() querypb.Type

Type returns the type of Value.

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