(j JSON, path []string, to JSON, createMissing bool)
| 2231 | } |
| 2232 | |
| 2233 | func 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 | |
| 2264 | var errCannotReplaceExistingKey = pgerror.WithCandidateCode(errors.New("cannot replace existing key"), pgcode.InvalidParameterValue) |
| 2265 |
no test coverage detected
searching dependent graphs…