Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyTransform(t Transformation, doc *Value, paths []*Path, values []*Value) error
- func MarshalSQLValue(buf []byte) (*sqltypes.Value, error)
- func MatchPath(rawJSON, rawPath []byte, match func(value *Value)) error
- type NumberType
- type Object
- func (o *Object) Add(key string, value *Value)
- func (cached *Object) CachedSize(alloc bool) int64
- func (o *Object) Del(key string)
- func (o *Object) Get(key string) *Value
- func (o *Object) Keys() []string
- func (o *Object) Len() int
- func (o *Object) MarshalTo(dst []byte) []byte
- func (o *Object) Set(key string, value *Value, t Transformation)
- func (o *Object) String() string
- func (o *Object) Visit(f func(key string, v *Value))
- type Parser
- type Path
- type PathParser
- type Transformation
- type Type
- type Value
- func NewArray(vals []*Value) *Value
- func NewBit(raw string) *Value
- func NewBlob(raw string) *Value
- func NewDate(raw string) *Value
- func NewDateTime(raw string) *Value
- func NewFromSQL(v sqltypes.Value) (*Value, error)
- func NewNumber(num string, n NumberType) *Value
- func NewObject(obj Object) *Value
- func NewOpaqueValue(raw string) *Value
- func NewString(raw string) *Value
- func NewTime(raw string) *Value
- func (v *Value) Array() ([]*Value, bool)
- func (v *Value) Bool() (bool, bool)
- func (cached *Value) CachedSize(alloc bool) int64
- func (v *Value) Date() (datetime.Date, bool)
- func (v *Value) DateTime() (datetime.DateTime, bool)
- func (v *Value) Decimal() (decimal.Decimal, bool)
- func (v *Value) DelArrayItem(n int)
- func (v *Value) Depth() int
- func (v *Value) Float64() (float64, bool)
- func (v *Value) Hash(h *vthash.Hasher)
- func (v *Value) Int64() (int64, bool)
- func (v *Value) Len() int
- func (v *Value) MarshalDate() string
- func (v *Value) MarshalDateTime() string
- func (v *Value) MarshalSQLTo(dst []byte) []byte
- func (v *Value) MarshalTime() string
- func (v *Value) MarshalTo(dst []byte) []byte
- func (v *Value) NumberType() NumberType
- func (v *Value) Object() (*Object, bool)
- func (v *Value) Raw() string
- func (v *Value) SQLType() sqltypes.Type
- func (v *Value) SetArrayItem(idx int, value *Value, t Transformation)
- func (v *Value) String() string
- func (v *Value) StringBytes() ([]byte, bool)
- func (v *Value) Time() (datetime.Time, bool)
- func (v *Value) ToBoolean() bool
- func (v *Value) ToRawBytes() []byte
- func (v *Value) ToUnencodedBytes() []byte
- func (v *Value) Type() Type
- func (v *Value) Uint64() (uint64, bool)
- func (v *Value) WeightString(dst []byte) []byte
Constants ¶
const ( JSON_KEY_NULL = '\x00' JSON_KEY_NUMBER_NEG = '\x01' JSON_KEY_NUMBER_ZERO = '\x02' JSON_KEY_NUMBER_POS = '\x03' JSON_KEY_STRING = '\x04' JSON_KEY_OBJECT = '\x05' JSON_KEY_ARRAY = '\x06' JSON_KEY_FALSE = '\x07' JSON_KEY_TRUE = '\x08' JSON_KEY_DATE = '\x09' JSON_KEY_TIME = '\x0A' JSON_KEY_DATETIME = '\x0B' JSON_KEY_OPAQUE = '\x0C' )
const MaxDepth = 300
MaxDepth is the maximum depth for nested JSON.
Variables ¶
var ( ValueTrue = &Value{t: TypeBoolean} ValueFalse = &Value{t: TypeBoolean} ValueNull = &Value{t: TypeNull} )
Functions ¶
func ApplyTransform ¶
func ApplyTransform(t Transformation, doc *Value, paths []*Path, values []*Value) error
func MarshalSQLValue ¶
MarshalSQLValue converts the byte representation of a json value and returns it formatted by MarshalSQLTo
Types ¶
type NumberType ¶
type NumberType int32
const ( NumberTypeUnknown NumberType = iota NumberTypeSigned NumberTypeUnsigned NumberTypeDecimal NumberTypeFloat )
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object represents JSON object.
Object cannot be used from concurrent goroutines. Use per-goroutine parsers or ParserPool instead.
func (*Object) CachedSize ¶
func (*Object) Get ¶
Get returns the value for the given key in the o.
Returns nil if the value for the given key isn't found.
The returned value is valid until Parse is called on the Parser returned o.
func (*Object) Set ¶
func (o *Object) Set(key string, value *Value, t Transformation)
Set sets (key, value) entry in the o.
The value must be unchanged during o lifetime.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses JSON.
Parser may be re-used for subsequent parsing.
Parser cannot be used from concurrent goroutines. Use per-goroutine parsers or ParserPool instead.
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
func (*Path) ContainsWildcards ¶
type PathParser ¶
type PathParser struct {
// contains filtered or unexported fields
}
func (*PathParser) ParseBytes ¶
func (p *PathParser) ParseBytes(in []byte) (*Path, error)
type Transformation ¶
type Transformation int
const ( Set Transformation = iota Insert Replace Remove )
type Type ¶
type Type int32
Type represents JSON type.
const ( // TypeNull is JSON null. TypeNull Type = iota // TypeNumber is JSON number type. TypeNumber // TypeString is JSON string type. TypeString // TypeObject is JSON object type. TypeObject // TypeArray is JSON array type. TypeArray // TypeBoolean is JSON boolean. TypeBoolean // TypeDate is JSON date. TypeDate // TypeTime is JSON time. TypeTime // TypeDateTime is JSON time. TypeDateTime // TypeOpaque is JSON opaque type. TypeOpaque // TypeBit is JSON bit string. TypeBit // TypeBlob is JSON blob. TypeBlob )
See https://dev.mysql.com/doc/refman/8.0/en/json.html#json-comparison for the ordering here
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value represents any JSON value.
Call Type in order to determine the actual type of the JSON value.
Value cannot be used from concurrent goroutines. Use per-goroutine parsers or ParserPool instead.
func NewDateTime ¶
func NewNumber ¶
func NewNumber(num string, n NumberType) *Value
func NewOpaqueValue ¶
func (*Value) Bool ¶
Bool returns the underlying JSON bool for the v.
Use GetBool if you don't need error handling.
func (*Value) CachedSize ¶
func (*Value) DelArrayItem ¶
func (*Value) MarshalDate ¶
func (*Value) MarshalDateTime ¶
func (*Value) MarshalSQLTo ¶
MarshalSQLTo appends marshaled v to dst and returns the result in the form like `JSON_OBJECT` or `JSON_ARRAY` to ensure we don't lose any type information.
func (*Value) MarshalTime ¶
func (*Value) NumberType ¶
func (v *Value) NumberType() NumberType
func (*Value) SetArrayItem ¶
func (v *Value) SetArrayItem(idx int, value *Value, t Transformation)
SetArrayItem sets the value in the array v at idx position.
The value must be unchanged during v lifetime.
func (*Value) String ¶
String returns string representation of the v.
The function is for debugging purposes only. It isn't optimized for speed. See MarshalTo instead.
Don't confuse this function with StringBytes, which must be called for obtaining the underlying JSON string for the v.
func (*Value) StringBytes ¶
StringBytes returns the underlying JSON string for the v.