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

Function deepInsert

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

Source from the content-addressed store, hash-verified

1224}
1225
1226func deepInsert(j JSON, path []string, to JSON, insertAfter bool) (JSON, error) {
1227 switch len(path) {
1228 case 0:
1229 return j, nil
1230 case 1:
1231 return insertValKeyOrIdx(j, path[0], to, insertAfter)
1232 default:
1233 switch v := j.(type) {
1234 case *jsonEncoded:
1235 n, err := v.shallowDecode()
1236 if err != nil {
1237 return nil, err
1238 }
1239 return deepInsert(n, path, to, insertAfter)
1240 default:
1241 fetched, err := j.FetchValKeyOrIdx(path[0])
1242 if err != nil {
1243 return nil, err
1244 }
1245 if fetched == nil {
1246 return j, nil
1247 }
1248 sub, err := deepInsert(fetched, path[1:], to, insertAfter)
1249 if err != nil {
1250 return nil, err
1251 }
1252 return setValKeyOrIdx(j, path[0], sub, true)
1253 }
1254 }
1255}
1256
1257func (j jsonObject) FetchValKeyOrIdx(key string) (JSON, error) {
1258 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…