(key string, to JSON, createMissing bool)
| 1364 | var errCannotDeleteFromObject = pgerror.WithCandidateCode(errors.New("cannot delete from object using integer index"), pgcode.InvalidParameterValue) |
| 1365 | |
| 1366 | func (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 | |
| 1394 | func (j jsonArray) RemoveString(s string) (JSON, bool, error) { |
| 1395 | b := NewArrayBuilder(j.Len()) |
no test coverage detected