Documentation ¶
Index ¶
- Constants
- Variables
- func CompareBinary(left, right BinaryJSON) int
- func ContainsBinary(obj, target BinaryJSON) bool
- func PeekBytesAsJSON(b []byte) (n int, err error)
- func UnquoteString(str string) (string, error)
- type BinaryJSON
- func (bj BinaryJSON) ArrayInsert(pathExpr PathExpression, value BinaryJSON) (res BinaryJSON, err error)
- func (bj BinaryJSON) Copy() BinaryJSON
- func (bj BinaryJSON) Extract(pathExprList []PathExpression) (ret BinaryJSON, found bool)
- func (bj BinaryJSON) GetElemCount() int
- func (bj BinaryJSON) GetElemDepth() int
- func (bj BinaryJSON) GetFloat64() float64
- func (bj BinaryJSON) GetInt64() int64
- func (bj BinaryJSON) GetKeys() BinaryJSON
- func (bj BinaryJSON) GetString() []byte
- func (bj BinaryJSON) GetUint64() uint64
- func (bj BinaryJSON) MarshalJSON() ([]byte, error)
- func (bj BinaryJSON) Modify(pathExprList []PathExpression, values []BinaryJSON, mt ModifyType) (retj BinaryJSON, err error)
- func (bj BinaryJSON) Remove(pathExprList []PathExpression) (BinaryJSON, error)
- func (bj BinaryJSON) Search(containType string, search string, escape byte, pathExpres []PathExpression) (res BinaryJSON, isNull bool, err error)
- func (bj BinaryJSON) String() string
- func (bj BinaryJSON) Type() string
- func (bj *BinaryJSON) UnmarshalJSON(data []byte) error
- func (bj BinaryJSON) Unquote() (string, error)
- func (bj BinaryJSON) Walk(walkFn BinaryJSONWalkFunc, pathExprList ...PathExpression) (err error)
- type BinaryJSONWalkFunc
- type ModifyType
- type PathExpression
- type TypeCode
Constants ¶
const ( // LiteralNil represents JSON null. LiteralNil byte = 0x00 // LiteralTrue represents JSON true. LiteralTrue byte = 0x01 // LiteralFalse represents JSON false. LiteralFalse byte = 0x02 )
const ( // 'all': 1 if all paths exist within the document, 0 otherwise. ContainsPathAll = "all" // 'one': 1 if at least one path exists within the document, 0 otherwise. ContainsPathOne = "one" )
json_contains_path function type choices See: https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html#function_json-contains-path
Variables ¶
var ( // ErrInvalidJSONText means invalid JSON text. ErrInvalidJSONText = terror.ClassJSON.New(mysql.ErrInvalidJSONText, mysql.MySQLErrName[mysql.ErrInvalidJSONText]) // ErrInvalidJSONPath means invalid JSON path. ErrInvalidJSONPath = terror.ClassJSON.New(mysql.ErrInvalidJSONPath, mysql.MySQLErrName[mysql.ErrInvalidJSONPath]) // ErrInvalidJSONData means invalid JSON data. ErrInvalidJSONData = terror.ClassJSON.New(mysql.ErrInvalidJSONData, mysql.MySQLErrName[mysql.ErrInvalidJSONData]) // ErrInvalidJSONPathWildcard means invalid JSON path that contain wildcard characters. ErrInvalidJSONPathWildcard = terror.ClassJSON.New(mysql.ErrInvalidJSONPathWildcard, mysql.MySQLErrName[mysql.ErrInvalidJSONPathWildcard]) // ErrInvalidJSONContainsPathType means invalid JSON contains path type. ErrInvalidJSONContainsPathType = terror.ClassJSON.New(mysql.ErrInvalidJSONContainsPathType, mysql.MySQLErrName[mysql.ErrInvalidJSONContainsPathType]) // ErrJSONDocumentNULLKey means that json's key is null ErrJSONDocumentNULLKey = terror.ClassJSON.New(mysql.ErrJSONDocumentNULLKey, mysql.MySQLErrName[mysql.ErrJSONDocumentNULLKey]) // ErrInvalidJSONPathArrayCell means invalid JSON path for an array cell. ErrInvalidJSONPathArrayCell = terror.ClassJSON.New(mysql.ErrInvalidJSONPathArrayCell, mysql.MySQLErrName[mysql.ErrInvalidJSONPathArrayCell]) // ErrUnsupportedSecondArgumentType means unsupported second argument type in json_objectagg ErrUnsupportedSecondArgumentType = terror.ClassJSON.New(mysql.ErrUnsupportedSecondArgumentType, mysql.MySQLErrName[mysql.ErrUnsupportedSecondArgumentType]) )
Functions ¶
func CompareBinary ¶
func CompareBinary(left, right BinaryJSON) int
CompareBinary compares two binary json objects. Returns -1 if left < right, 0 if left == right, else returns 1.
func ContainsBinary ¶
func ContainsBinary(obj, target BinaryJSON) bool
ContainsBinary check whether JSON document contains specific target according the following rules: 1) object contains a target object if and only if every key is contained in source object and the value associated with the target key is contained in the value associated with the source key; 2) array contains a target nonarray if and only if the target is contained in some element of the array; 3) array contains a target array if and only if every element is contained in some element of the array; 4) scalar contains a target scalar if and only if they are comparable and are equal;
func PeekBytesAsJSON ¶
PeekBytesAsJSON trys to peek some bytes from b, until we can deserialize a JSON from those bytes.
func UnquoteString ¶
UnquoteString remove quotes in a string, including the quotes at the head and tail of string.
Types ¶
type BinaryJSON ¶
BinaryJSON represents a binary encoded JSON object. It can be randomly accessed without deserialization.
func CreateBinary ¶
func CreateBinary(in interface{}) BinaryJSON
CreateBinary creates a BinaryJSON from interface.
func MergeBinary ¶
func MergeBinary(bjs []BinaryJSON) BinaryJSON
MergeBinary merges multiple BinaryJSON into one according the following rules: 1) adjacent arrays are merged to a single array; 2) adjacent object are merged to a single object; 3) a scalar value is autowrapped as an array before merge; 4) an adjacent array and object are merged by autowrapping the object as an array.
func ParseBinaryFromString ¶
func ParseBinaryFromString(s string) (bj BinaryJSON, err error)
ParseBinaryFromString parses a json from string.
func (BinaryJSON) ArrayInsert ¶
func (bj BinaryJSON) ArrayInsert(pathExpr PathExpression, value BinaryJSON) (res BinaryJSON, err error)
ArrayInsert insert a BinaryJSON into the given array cell. All path expressions cannot contain * or ** wildcard. If any error occurs, the input won't be changed.
func (BinaryJSON) Extract ¶
func (bj BinaryJSON) Extract(pathExprList []PathExpression) (ret BinaryJSON, found bool)
Extract receives several path expressions as arguments, matches them in bj, and returns:
ret: target JSON matched any path expressions. maybe autowrapped as an array. found: true if any path expressions matched.
func (BinaryJSON) GetElemCount ¶
func (bj BinaryJSON) GetElemCount() int
GetElemCount gets the count of Object or Array.
func (BinaryJSON) GetElemDepth ¶
func (bj BinaryJSON) GetElemDepth() int
GetElemDepth for JSON_DEPTH Returns the maximum depth of a JSON document rules referenced by MySQL JSON_DEPTH function [https://dev.mysql.com/doc/refman/5.7/en/json-attribute-functions.html#function_json-depth] 1) An empty array, empty object, or scalar value has depth 1. 2) A nonempty array containing only elements of depth 1 or nonempty object containing only member values of depth 1 has depth 2. 3) Otherwise, a JSON document has depth greater than 2. e.g. depth of '{}', '[]', 'true': 1 e.g. depth of '[10, 20]', '[[], {}]': 2 e.g. depth of '[10, {"a": 20}]': 3
func (BinaryJSON) GetFloat64 ¶
func (bj BinaryJSON) GetFloat64() float64
GetFloat64 gets the float64 value.
func (BinaryJSON) GetKeys ¶
func (bj BinaryJSON) GetKeys() BinaryJSON
GetKeys gets the keys of the object
func (BinaryJSON) GetString ¶
func (bj BinaryJSON) GetString() []byte
GetString gets the string value.
func (BinaryJSON) GetUint64 ¶
func (bj BinaryJSON) GetUint64() uint64
GetUint64 gets the uint64 value.
func (BinaryJSON) MarshalJSON ¶
func (bj BinaryJSON) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (BinaryJSON) Modify ¶
func (bj BinaryJSON) Modify(pathExprList []PathExpression, values []BinaryJSON, mt ModifyType) (retj BinaryJSON, err error)
Modify modifies a JSON object by insert, replace or set. All path expressions cannot contain * or ** wildcard. If any error occurs, the input won't be changed.
func (BinaryJSON) Remove ¶
func (bj BinaryJSON) Remove(pathExprList []PathExpression) (BinaryJSON, error)
Remove removes the elements indicated by pathExprList from JSON.
func (BinaryJSON) Search ¶
func (bj BinaryJSON) Search(containType string, search string, escape byte, pathExpres []PathExpression) (res BinaryJSON, isNull bool, err error)
Search for JSON_Search rules referenced by MySQL JSON_SEARCH function [https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html#function_json-search]
func (BinaryJSON) String ¶
func (bj BinaryJSON) String() string
String implements fmt.Stringer interface.
func (BinaryJSON) Type ¶
func (bj BinaryJSON) Type() string
Type returns type of BinaryJSON as string.
func (*BinaryJSON) UnmarshalJSON ¶
func (bj *BinaryJSON) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
func (BinaryJSON) Unquote ¶
func (bj BinaryJSON) Unquote() (string, error)
Unquote is for JSON_UNQUOTE.
func (BinaryJSON) Walk ¶
func (bj BinaryJSON) Walk(walkFn BinaryJSONWalkFunc, pathExprList ...PathExpression) (err error)
Walk traverse BinaryJSON objects
type BinaryJSONWalkFunc ¶
type BinaryJSONWalkFunc func(fullpath PathExpression, bj BinaryJSON) (stop bool, err error)
BinaryJSONWalkFunc is used as callback function for BinaryJSON.Walk
type ModifyType ¶
type ModifyType byte
ModifyType is for modify a JSON. There are three valid values: ModifyInsert, ModifyReplace and ModifySet.
const ( // ModifyInsert is for insert a new element into a JSON. ModifyInsert ModifyType = 0x01 // ModifyReplace is for replace an old elemList from a JSON. ModifyReplace ModifyType = 0x02 // ModifySet = ModifyInsert | ModifyReplace ModifySet ModifyType = 0x03 )
type PathExpression ¶
type PathExpression struct {
// contains filtered or unexported fields
}
PathExpression is for JSON path expression.
func ParseJSONPathExpr ¶
func ParseJSONPathExpr(pathExpr string) (pe PathExpression, err error)
ParseJSONPathExpr parses a JSON path expression. Returns a PathExpression object which can be used in JSON_EXTRACT, JSON_SET and so on.
func (PathExpression) ContainsAnyAsterisk ¶
func (pe PathExpression) ContainsAnyAsterisk() bool
ContainsAnyAsterisk returns true if pe contains any asterisk.
func (PathExpression) String ¶
func (pe PathExpression) String() string
type TypeCode ¶
type TypeCode = byte
TypeCode indicates JSON type.
const ( // TypeCodeObject indicates the JSON is an object. TypeCodeObject TypeCode = 0x01 // TypeCodeArray indicates the JSON is an array. TypeCodeArray TypeCode = 0x03 // TypeCodeLiteral indicates the JSON is a literal. TypeCodeLiteral TypeCode = 0x04 // TypeCodeInt64 indicates the JSON is a signed integer. TypeCodeInt64 TypeCode = 0x09 // TypeCodeUint64 indicates the JSON is a unsigned integer. TypeCodeUint64 TypeCode = 0x0a // TypeCodeFloat64 indicates the JSON is a double float number. TypeCodeFloat64 TypeCode = 0x0b // TypeCodeString indicates the JSON is a string. TypeCodeString TypeCode = 0x0c )