MCPcopy Create free account
hub / github.com/dolthub/doltgresql / SetKey

Method SetKey

postgres/parser/json/json.go:1366–1392  ·  view source on GitHub ↗
(key string, to JSON, createMissing bool)

Source from the content-addressed store, hash-verified

1364var errCannotDeleteFromObject = pgerror.WithCandidateCode(errors.New("cannot delete from object using integer index"), pgcode.InvalidParameterValue)
1365
1366func (j jsonObject) SetKey(key string, to JSON, createMissing bool) (jsonObject, error) {
1367 result := make(jsonObject, 0, len(j)+1)
1368 curIdx := 0
1369
1370 for curIdx < len(j) && string(j[curIdx].k) < key {
1371 result = append(result, j[curIdx])
1372 curIdx++
1373 }
1374
1375 keyAlreadyExists := curIdx < len(j) && string(j[curIdx].k) == key
1376 if createMissing || keyAlreadyExists {
1377 result = append(result, jsonKeyValuePair{
1378 k: jsonString(key),
1379 v: to,
1380 })
1381 }
1382 if keyAlreadyExists {
1383 curIdx++
1384 }
1385
1386 for curIdx < len(j) {
1387 result = append(result, j[curIdx])
1388 curIdx++
1389 }
1390
1391 return result, nil
1392}
1393
1394func (j jsonArray) RemoveString(s string) (JSON, bool, error) {
1395 b := NewArrayBuilder(j.Len())

Callers 2

setValKeyOrIdxFunction · 0.80
insertValKeyOrIdxFunction · 0.80

Calls 1

jsonStringTypeAlias · 0.85

Tested by

no test coverage detected