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

Method SetKey

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

Source from the content-addressed store, hash-verified

1279var errCannotDeleteFromObject = pgerror.WithCandidateCode(errors.New("cannot delete from object using integer index"), pgcode.InvalidParameterValue)
1280
1281func (j jsonObject) SetKey(key string, to JSON, createMissing bool) (jsonObject, error) {
1282 result := make(jsonObject, 0, len(j)+1)
1283 curIdx := 0
1284
1285 for curIdx < len(j) && string(j[curIdx].k) < key {
1286 result = append(result, j[curIdx])
1287 curIdx++
1288 }
1289
1290 keyAlreadyExists := curIdx < len(j) && string(j[curIdx].k) == key
1291 if createMissing || keyAlreadyExists {
1292 result = append(result, jsonKeyValuePair{
1293 k: jsonString(key),
1294 v: to,
1295 })
1296 }
1297 if keyAlreadyExists {
1298 curIdx++
1299 }
1300
1301 for curIdx < len(j) {
1302 result = append(result, j[curIdx])
1303 curIdx++
1304 }
1305
1306 return result, nil
1307}
1308
1309func (j jsonArray) RemoveString(s string) (JSON, bool, error) {
1310 b := NewArrayBuilder(j.Len())

Callers 2

setValKeyOrIdxFunction · 0.80
insertValKeyOrIdxFunction · 0.80

Calls 1

jsonStringTypeAlias · 0.85

Tested by

no test coverage detected