(res types.BinaryJSON, p string, v types.BinaryJSON)
| 1129 | } |
| 1130 | |
| 1131 | func (b *builtinJSONArrayAppendSig) appendJSONArray(res types.BinaryJSON, p string, v types.BinaryJSON) (types.BinaryJSON, bool, error) { |
| 1132 | // We should do the following checks to get correct values in res.Extract |
| 1133 | pathExpr, err := types.ParseJSONPathExpr(p) |
| 1134 | if err != nil { |
| 1135 | return res, true, err |
| 1136 | } |
| 1137 | if pathExpr.CouldMatchMultipleValues() { |
| 1138 | return res, true, types.ErrInvalidJSONPathMultipleSelection |
| 1139 | } |
| 1140 | |
| 1141 | obj, exists := res.Extract([]types.JSONPathExpression{pathExpr}) |
| 1142 | if !exists { |
| 1143 | // If path not exists, just do nothing and no errors. |
| 1144 | return res, false, nil |
| 1145 | } |
| 1146 | |
| 1147 | if obj.TypeCode != types.JSONTypeCodeArray { |
| 1148 | // res.Extract will return a json object instead of an array if there is an object at path pathExpr. |
| 1149 | // JSON_ARRAY_APPEND({"a": "b"}, "$", {"b": "c"}) => [{"a": "b"}, {"b", "c"}] |
| 1150 | // We should wrap them to a single array first. |
| 1151 | obj, err = types.CreateBinaryJSONWithCheck([]any{obj}) |
| 1152 | if err != nil { |
| 1153 | return res, true, err |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | obj = types.MergeBinaryJSON([]types.BinaryJSON{obj, v}) |
| 1158 | res, err = res.Modify([]types.JSONPathExpression{pathExpr}, []types.BinaryJSON{obj}, types.JSONModifySet) |
| 1159 | return res, false, err |
| 1160 | } |
| 1161 | |
| 1162 | type jsonArrayInsertFunctionClass struct { |
| 1163 | baseFunctionClass |
no test coverage detected