MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / deepSet

Function deepSet

pkg/util/json/json.go:2233–2262  ·  view source on GitHub ↗
(j JSON, path []string, to JSON, createMissing bool)

Source from the content-addressed store, hash-verified

2231}
2232
2233func deepSet(j JSON, path []string, to JSON, createMissing bool) (JSON, error) {
2234 switch len(path) {
2235 case 0:
2236 return j, nil
2237 case 1:
2238 return setValKeyOrIdx(j, path[0], to, createMissing)
2239 default:
2240 switch v := j.(type) {
2241 case *jsonEncoded:
2242 n, err := v.shallowDecode()
2243 if err != nil {
2244 return nil, err
2245 }
2246 return deepSet(n, path, to, createMissing)
2247 default:
2248 fetched, err := j.FetchValKeyOrIdx(path[0])
2249 if err != nil {
2250 return nil, err
2251 }
2252 if fetched == nil {
2253 return j, nil
2254 }
2255 sub, err := deepSet(fetched, path[1:], to, createMissing)
2256 if err != nil {
2257 return nil, err
2258 }
2259 return setValKeyOrIdx(j, path[0], sub, createMissing)
2260 }
2261 }
2262}
2263
2264var errCannotReplaceExistingKey = pgerror.WithCandidateCode(errors.New("cannot replace existing key"), pgcode.InvalidParameterValue)
2265

Callers 1

DeepSetFunction · 0.85

Calls 3

setValKeyOrIdxFunction · 0.85
shallowDecodeMethod · 0.80
FetchValKeyOrIdxMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…