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

Method SetKey

pkg/util/json/json.go:2376–2402  ·  view source on GitHub ↗
(key string, to JSON, createMissing bool)

Source from the content-addressed store, hash-verified

2374var errCannotDeleteFromObject = pgerror.WithCandidateCode(errors.New("cannot delete from object using integer index"), pgcode.InvalidParameterValue)
2375
2376func (j jsonObject) SetKey(key string, to JSON, createMissing bool) (jsonObject, error) {
2377 result := make(jsonObject, 0, len(j)+1)
2378 curIdx := 0
2379
2380 for curIdx < len(j) && string(j[curIdx].k) < key {
2381 result = append(result, j[curIdx])
2382 curIdx++
2383 }
2384
2385 keyAlreadyExists := curIdx < len(j) && string(j[curIdx].k) == key
2386 if createMissing || keyAlreadyExists {
2387 result = append(result, jsonKeyValuePair{
2388 k: jsonString(key),
2389 v: to,
2390 })
2391 }
2392 if keyAlreadyExists {
2393 curIdx++
2394 }
2395
2396 for curIdx < len(j) {
2397 result = append(result, j[curIdx])
2398 curIdx++
2399 }
2400
2401 return result, nil
2402}
2403
2404func (j jsonArray) RemoveString(s string) (JSON, bool, error) {
2405 b := NewArrayBuilder(j.Len())

Callers 2

setValKeyOrIdxFunction · 0.80
insertValKeyOrIdxFunction · 0.80

Calls 1

jsonStringTypeAlias · 0.85

Tested by

no test coverage detected