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

Function deepInsert

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

Source from the content-addressed store, hash-verified

2319}
2320
2321func deepInsert(j JSON, path []string, to JSON, insertAfter bool) (JSON, error) {
2322 switch len(path) {
2323 case 0:
2324 return j, nil
2325 case 1:
2326 return insertValKeyOrIdx(j, path[0], to, insertAfter)
2327 default:
2328 switch v := j.(type) {
2329 case *jsonEncoded:
2330 n, err := v.shallowDecode()
2331 if err != nil {
2332 return nil, err
2333 }
2334 return deepInsert(n, path, to, insertAfter)
2335 default:
2336 fetched, err := j.FetchValKeyOrIdx(path[0])
2337 if err != nil {
2338 return nil, err
2339 }
2340 if fetched == nil {
2341 return j, nil
2342 }
2343 sub, err := deepInsert(fetched, path[1:], to, insertAfter)
2344 if err != nil {
2345 return nil, err
2346 }
2347 return setValKeyOrIdx(j, path[0], sub, true)
2348 }
2349 }
2350}
2351
2352func (j jsonObject) FetchValKeyOrIdx(key string) (JSON, error) {
2353 return j.FetchValKey(key)

Callers 1

DeepInsertFunction · 0.85

Calls 4

insertValKeyOrIdxFunction · 0.85
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…