sqltypes

package
v0.0.0-...-5c6c1e7 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Null      = Type_NULL_TYPE
	Int8      = Type_INT8
	Uint8     = Type_UINT8
	Int16     = Type_INT16
	Uint16    = Type_UINT16
	Int32     = Type_INT32
	Uint32    = Type_UINT32
	Int64     = Type_INT64
	Uint64    = Type_UINT64
	Float32   = Type_FLOAT32
	Float64   = Type_FLOAT64
	Timestamp = Type_TIMESTAMP
	Date      = Type_DATE
	Time      = Type_TIME
	Datetime  = Type_DATETIME
	Year      = Type_YEAR
	Decimal   = Type_DECIMAL
	Text      = Type_TEXT
	Blob      = Type_BLOB
	VarChar   = Type_VARCHAR
	VarBinary = Type_VARBINARY
	Char      = Type_CHAR
	Binary    = Type_BINARY
	Bit       = Type_BIT
	TypeJSON  = Type_JSON
)

Vitess data types. These are idiomatically named synonyms for the 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 Flag_name = map[int32]string{
	0:    "NONE",
	256:  "ISINTEGRAL",
	512:  "ISUNSIGNED",
	1024: "ISFLOAT",
	2048: "ISQUOTED",
	4096: "ISTEXT",
	8192: "ISBINARY",
}
View Source
var Flag_value = map[string]int32{
	"NONE":       0,
	"ISINTEGRAL": 256,
	"ISUNSIGNED": 512,
	"ISFLOAT":    1024,
	"ISQUOTED":   2048,
	"ISTEXT":     4096,
	"ISBINARY":   8192,
}

Functions

func BytesToString

func BytesToString(b []byte) (s string)

BytesToString casts slice to string without copy

func IsBinary

func IsBinary(t Type) bool

IsBinary returns true if Type is a binary. If you have a Value object, use its member function.

func IsFloat

func IsFloat(t Type) bool

IsFloat returns true is Type is a floating point. If you have a Value object, use its member function.

func IsIntegral

func IsIntegral(t Type) bool

IsIntegral returns true if Type is an integral (signed/unsigned) that can be represented using up to 64 binary bits. If you have a Value object, use its member function.

func IsQuoted

func IsQuoted(t Type) bool

IsQuoted returns true if Type is a quoted text or binary. If you have a Value object, use its member function.

func IsSigned

func IsSigned(t Type) bool

IsSigned returns true if Type is a signed integral. If you have a Value object, use its member function.

func IsTemporal

func IsTemporal(t Type) bool

IsTemporal returns true if Value is time type.

func IsText

func IsText(t Type) bool

IsText returns true if Type is a text. If you have a Value object, use its member function.

func IsUnsigned

func IsUnsigned(t Type) bool

IsUnsigned returns true if Type is an unsigned integral. Caution: this is not the same as !IsSigned. If you have a Value object, use its member function.

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes casts string to slice without copy

Types

type BindVariable

type BindVariable struct {
	Type  Type   `protobuf:"varint,1,opt,name=type,enum=query.Type" json:"type,omitempty"`
	Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
	// values are set if type is TUPLE.
	Values []*Value `protobuf:"bytes,3,rep,name=values" json:"values,omitempty"`
}

BindVariable represents a single bind variable in a Query.

type Flag

type Flag int32

Flag allows us to qualify types by their common properties.

const (
	Flag_NONE       Flag = 0
	Flag_ISINTEGRAL Flag = 256
	Flag_ISUNSIGNED Flag = 512
	Flag_ISFLOAT    Flag = 1024
	Flag_ISQUOTED   Flag = 2048
	Flag_ISTEXT     Flag = 4096
	Flag_ISBINARY   Flag = 8192
)

type Type

type Type int32

Type defines the various supported data types in bind vars and query results.

const (
	// NULL_TYPE specifies a NULL type.
	Type_NULL_TYPE Type = 0
	// INT8 specifies a TINYINT type.
	// Properties: 1, IsNumber.
	Type_INT8 Type = 257
	// UINT8 specifies a TINYINT UNSIGNED type.
	// Properties: 2, IsNumber, IsUnsigned.
	Type_UINT8 Type = 770
	// INT16 specifies a SMALLINT type.
	// Properties: 3, IsNumber.
	Type_INT16 Type = 259
	// UINT16 specifies a SMALLINT UNSIGNED type.
	// Properties: 4, IsNumber, IsUnsigned.
	Type_UINT16 Type = 772
	// INT24 specifies a MEDIUMINT type.
	// Properties: 5, IsNumber.
	Type_INT32 Type = 263
	// UINT32 specifies a INTEGER UNSIGNED type.
	// Properties: 8, IsNumber, IsUnsigned.
	Type_UINT32 Type = 776
	// INT64 specifies a BIGINT type.
	// Properties: 9, IsNumber.
	Type_INT64 Type = 265
	// UINT64 specifies a BIGINT UNSIGNED type.
	// Properties: 10, IsNumber, IsUnsigned.
	Type_UINT64 Type = 778
	// FLOAT32 specifies a FLOAT type.
	// Properties: 11, IsFloat.
	Type_FLOAT32 Type = 1035
	// FLOAT64 specifies a DOUBLE or REAL type.
	// Properties: 12, IsFloat.
	Type_FLOAT64 Type = 1036
	// TIMESTAMP specifies a TIMESTAMP type.
	// Properties: 13, IsQuoted.
	Type_TIMESTAMP Type = 2061
	// DATE specifies a DATE type.
	// Properties: 14, IsQuoted.
	Type_DATE Type = 2062
	// TIME specifies a TIME type.
	// Properties: 15, IsQuoted.
	Type_TIME Type = 2063
	// DATETIME specifies a DATETIME type.
	// Properties: 16, IsQuoted.
	Type_DATETIME Type = 2064
	// YEAR specifies a YEAR type.
	// Properties: 17, IsNumber, IsUnsigned.
	Type_YEAR Type = 785
	// DECIMAL specifies a DECIMAL or NUMERIC type.
	// Properties: 18, None.
	Type_DECIMAL Type = 18
	// TEXT specifies a TEXT type.
	// Properties: 19, IsQuoted, IsText.
	Type_TEXT Type = 6163
	// BLOB specifies a BLOB type.
	// Properties: 20, IsQuoted, IsBinary.
	Type_BLOB Type = 10260
	// VARCHAR specifies a VARCHAR type.
	// Properties: 21, IsQuoted, IsText.
	Type_VARCHAR Type = 6165
	// VARBINARY specifies a VARBINARY type.
	// Properties: 22, IsQuoted, IsBinary.
	Type_VARBINARY Type = 10262
	// CHAR specifies a CHAR type.
	// Properties: 23, IsQuoted, IsText.
	Type_CHAR Type = 6167
	// BINARY specifies a BINARY type.
	// Properties: 24, IsQuoted, IsBinary.
	Type_BINARY Type = 10264
	// BIT specifies a BIT type.
	// Properties: 25, IsQuoted.
	Type_BIT Type = 2073
	// JSON specifies a JSON type.
	// Properties: 30, IsQuoted.
	Type_JSON Type = 2078
)

type Value

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

func BuildConverted

func BuildConverted(typ 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 representation. 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 Type, val []byte) Value

MakeTrusted makes a new Value based on the type. 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. Exceptions: The current package and mysql package do not need comments. Other packages can also use the function to create VarBinary or VarChar values.

func NewFloat32

func NewFloat32(v float32) Value

NewFloat32 builds an Float64 Value.

func NewFloat64

func NewFloat64(v float64) Value

NewFloat64 builds an Float64 Value.

func NewInt32

func NewInt32(v int32) Value

NewInt32 builds an Int64 Value.

func NewInt64

func NewInt64(v int64) Value

NewInt64 builds an Int64 Value.

func NewIntegral

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

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

func NewUint64

func NewUint64(v uint64) Value

NewUint64 builds an Uint64 Value.

func NewValue

func NewValue(typ Type, val []byte) (v Value, err error)

NewValue builds a Value using typ and val. If the value and typ don't match, it returns an error.

func NewVarBinary

func NewVarBinary(v string) Value

NewVarBinary builds a VarBinary Value. The input is a string because it's the most common use case.

func NewVarChar

func NewVarChar(v string) Value

NewVarChar builds a VarChar Value.

func ValueFromBytes

func ValueFromBytes(typ 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 canonical form. Otherwise, the original representation is preserved.

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

func (v Value) IsTemporal() bool

IsTemporal returns true if Value is time type.

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

func (v Value) ToString() string

ToString returns the value as MySQL would return it as string. If the value is not convertible like in the case of Expression, it returns nil.

func (Value) Type

func (v Value) Type() Type

Type returns the type of Value.

type Values

type Values []Value

Values represents the array of Value.

func (Values) Len

func (vs Values) Len() int

Len implements the interface.

Jump to

Keyboard shortcuts

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