(other JSON)
| 506 | } |
| 507 | |
| 508 | func (j jsonObject) Compare(other JSON) (int, error) { |
| 509 | cmp := cmpJSONTypes(j.Type(), other.Type()) |
| 510 | if cmp != 0 { |
| 511 | return cmp, nil |
| 512 | } |
| 513 | lenJ := j.Len() |
| 514 | lenO := other.Len() |
| 515 | if lenJ < lenO { |
| 516 | return -1, nil |
| 517 | } |
| 518 | if lenJ > lenO { |
| 519 | return 1, nil |
| 520 | } |
| 521 | // TODO(justin): we should optimize this, we don't have to decode the whole thing. |
| 522 | var err error |
| 523 | if other, err = decodeIfNeeded(other); err != nil { |
| 524 | return 0, err |
| 525 | } |
| 526 | o := other.(jsonObject) |
| 527 | for i := 0; i < lenJ; i++ { |
| 528 | cmpKey, err := j[i].k.Compare(o[i].k) |
| 529 | if err != nil { |
| 530 | return 0, err |
| 531 | } |
| 532 | if cmpKey != 0 { |
| 533 | return cmpKey, nil |
| 534 | } |
| 535 | cmpVal, err := j[i].v.Compare(o[i].v) |
| 536 | if err != nil { |
| 537 | return 0, err |
| 538 | } |
| 539 | if cmpVal != 0 { |
| 540 | return cmpVal, nil |
| 541 | } |
| 542 | } |
| 543 | return 0, nil |
| 544 | } |
| 545 | |
| 546 | var errTrailingCharacters = pgerror.WithCandidateCode(errors.New("trailing characters after JSON document"), pgcode.InvalidTextRepresentation) |
| 547 |
nothing calls this directly
no test coverage detected