Documentation ¶
Overview ¶
Package sqltypes implements interfaces and types that represent SQL values.
Index ¶
- Constants
- Variables
- func EventTokenMinimum(ev1, ev2 *querypb.EventToken) *querypb.EventToken
- func IncludeFieldsOrDefault(options *querypb.ExecuteOptions) querypb.ExecuteOptions_IncludedFields
- func IsBinary(t querypb.Type) bool
- func IsFloat(t querypb.Type) bool
- func IsIntegral(t querypb.Type) bool
- func IsQuoted(t querypb.Type) bool
- func IsSigned(t querypb.Type) bool
- func IsText(t querypb.Type) bool
- func IsUnsigned(t querypb.Type) bool
- func MySQLToType(mysqlType, flags int64) (typ querypb.Type, err error)
- func QueryResponsesToProto3(qr []QueryResponse) []*querypb.ResultWithError
- func ResultToProto3(qr *Result) *querypb.QueryResult
- func ResultsToProto3(qr []Result) []*querypb.QueryResult
- func RowToProto3(row []Value) *querypb.Row
- func RowsToProto3(rows [][]Value) []*querypb.Row
- func TypeToMySQL(typ querypb.Type) (mysqlType, flags int64)
- type BinWriter
- type QueryResponse
- type Result
- type ResultStream
- type Value
- func BuildConverted(typ querypb.Type, goval interface{}) (v Value, err error)
- func BuildIntegral(val string) (n Value, err error)
- func BuildValue(goval interface{}) (v Value, err error)
- func MakeRowTrusted(fields []*querypb.Field, row *querypb.Row) []Value
- func MakeString(val []byte) Value
- func MakeTrusted(typ querypb.Type, val []byte) Value
- func ValueFromBytes(typ querypb.Type, val []byte) (v Value, err error)
- func (v Value) EncodeASCII(b BinWriter)
- func (v Value) EncodeSQL(b BinWriter)
- func (v Value) IsBinary() bool
- func (v Value) IsFloat() bool
- func (v Value) IsIntegral() bool
- func (v Value) IsNull() bool
- func (v Value) IsQuoted() bool
- func (v Value) IsSigned() bool
- func (v Value) IsText() bool
- func (v Value) IsUnsigned() bool
- func (v Value) Len() int
- func (v Value) MarshalJSON() ([]byte, error)
- func (v Value) ParseFloat64() (val float64, err error)
- func (v Value) ParseInt64() (val int64, err error)
- func (v Value) ParseUint64() (val uint64, err error)
- func (v Value) Raw() []byte
- func (v Value) String() string
- func (v Value) ToNative() interface{}
- func (v Value) ToProtoValue() *querypb.Value
- func (v Value) Type() querypb.Type
- func (v *Value) UnmarshalJSON(b []byte) error
Constants ¶
const ( Null = querypb.Type_NULL_TYPE Int8 = querypb.Type_INT8 Uint8 = querypb.Type_UINT8 Int16 = querypb.Type_INT16 Uint16 = querypb.Type_UINT16 Int24 = querypb.Type_INT24 Uint24 = querypb.Type_UINT24 Int32 = querypb.Type_INT32 Uint32 = querypb.Type_UINT32 Int64 = querypb.Type_INT64 Uint64 = querypb.Type_UINT64 Float32 = querypb.Type_FLOAT32 Float64 = querypb.Type_FLOAT64 Timestamp = querypb.Type_TIMESTAMP Date = querypb.Type_DATE Time = querypb.Type_TIME Datetime = querypb.Type_DATETIME Year = querypb.Type_YEAR Decimal = querypb.Type_DECIMAL Text = querypb.Type_TEXT Blob = querypb.Type_BLOB VarChar = querypb.Type_VARCHAR VarBinary = querypb.Type_VARBINARY Char = querypb.Type_CHAR Binary = querypb.Type_BINARY Bit = querypb.Type_BIT Enum = querypb.Type_ENUM Set = querypb.Type_SET Tuple = querypb.Type_TUPLE Geometry = querypb.Type_GEOMETRY TypeJSON = querypb.Type_JSON )
Vitess data types. These are idiomatically named synonyms for the querypb.Type values.
Variables ¶
var ( // NULL represents the NULL value. NULL = Value{} // DontEscape tells you if a character should not be escaped. DontEscape = byte(255) )
var SQLDecodeMap [256]byte
SQLDecodeMap is the reverse of SQLEncodeMap
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 IncludeFieldsOrDefault ¶
func IncludeFieldsOrDefault(options *querypb.ExecuteOptions) querypb.ExecuteOptions_IncludedFields
IncludeFieldsOrDefault normalizes the passed Execution Options. It returns the default value if options is nil.
func IsIntegral ¶
IsIntegral returns true if querypb.Type is an integral (signed/unsigned) that can be represented using up to 64 binary bits.
func IsUnsigned ¶
IsUnsigned returns true if querypb.Type is an unsigned integral. Caution: this is not the same as !IsSigned.
func MySQLToType ¶
MySQLToType computes the vitess type from mysql type and flags.
func QueryResponsesToProto3 ¶
func QueryResponsesToProto3(qr []QueryResponse) []*querypb.ResultWithError
QueryResponsesToProto3 converts []QueryResponse to proto3.
func ResultToProto3 ¶
func ResultToProto3(qr *Result) *querypb.QueryResult
ResultToProto3 converts Result to proto3.
func ResultsToProto3 ¶
func ResultsToProto3(qr []Result) []*querypb.QueryResult
ResultsToProto3 converts []Result to proto3.
func RowToProto3 ¶
RowToProto3 converts []Value to proto3.
func RowsToProto3 ¶
RowsToProto3 converts [][]Value to proto3.
func TypeToMySQL ¶
TypeToMySQL returns the equivalent mysql type and flag for a vitess type.
Types ¶
type BinWriter ¶
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 QueryResponse ¶
QueryResponse represents a query response for ExecuteBatch.
func Proto3ToQueryReponses ¶
func Proto3ToQueryReponses(qr []*querypb.ResultWithError) []QueryResponse
Proto3ToQueryReponses converts proto3 queryResponse to []QueryResponse.
type Result ¶
type Result struct { Fields []*querypb.Field `json:"fields"` RowsAffected uint64 `json:"rows_affected"` InsertID uint64 `json:"insert_id"` Rows [][]Value `json:"rows"` Extras *querypb.ResultExtras `json:"extras"` }
Result represents a query result.
func CustomProto3ToResult ¶
func CustomProto3ToResult(fields []*querypb.Field, qr *querypb.QueryResult) *Result
CustomProto3ToResult converts a proto3 Result to an internal data structure. This function takes a separate fields input because not all QueryResults contain the field info. In particular, only the first packet of streaming queries contain the field info.
func Proto3ToResult ¶
func Proto3ToResult(qr *querypb.QueryResult) *Result
Proto3ToResult converts a proto3 Result to an internal data structure. This function should be used only if the field info is populated in qr.
func Proto3ToResults ¶
func Proto3ToResults(qr []*querypb.QueryResult) []Result
Proto3ToResults converts proto3 results to []Result.
func (*Result) AppendResult ¶
AppendResult will combine the Results Objects of one result to another result.Note currently it doesn't handle cases like if two results have different fields.We will enhance this function.
func (*Result) Repair ¶
Repair fixes the type info in the rows to conform to the supplied field types.
func (*Result) StripMetadata ¶
func (result *Result) StripMetadata(incl querypb.ExecuteOptions_IncludedFields) *Result
StripMetadata will return a new Result that has the same Rows, but the Field objects will have their non-critical metadata emptied. Note we don't proto.Copy each Field for performance reasons, but we only copy the individual fields.
type ResultStream ¶
type ResultStream interface { // Recv returns the next result on the stream. // It will return io.EOF if the stream ended. Recv() (*Result, error) }
ResultStream is an interface for receiving Result. It is used for RPC interfaces.
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 ¶
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 ¶
BuildIntegral builds an integral type from a string representaion. The type will be Int64 or Uint64. Int64 will be preferred where possible.
func BuildValue ¶
BuildValue builds a value from any go type. sqltype.Value is also allowed.
func MakeRowTrusted ¶
MakeRowTrusted converts a *querypb.Row to []Value based on the types in fields. It does not sanity check the values against the type. Every place this function is called, a comment is needed that explains why it's justified.
func MakeTrusted ¶
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 ¶
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 ¶
EncodeASCII encodes the value using 7-bit clean ascii bytes.
func (Value) IsIntegral ¶
IsIntegral returns true if Value is an integral.
func (Value) IsUnsigned ¶
IsUnsigned returns true if Value is an unsigned integral.
func (Value) MarshalJSON ¶
MarshalJSON should only be used for testing. It's not a complete implementation.
func (Value) ParseFloat64 ¶
ParseFloat64 will parse a Value into an float64. It does not check the type.
func (Value) ParseInt64 ¶
ParseInt64 will parse a Value into an int64. It does not check the type.
func (Value) ParseUint64 ¶
ParseUint64 will parse a Value into a uint64. It does not check the type.
func (Value) Raw ¶
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) 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 ¶
ToProtoValue converts Value to a querypb.Value.
func (*Value) UnmarshalJSON ¶
UnmarshalJSON should only be used for testing. It's not a complete implementation.