(other JSON)
| 456 | } |
| 457 | |
| 458 | func (j jsonObject) Compare(other JSON) (int, error) { |
| 459 | cmp := cmpJSONTypes(j.Type(), other.Type()) |
| 460 | if cmp != 0 { |
| 461 | return cmp, nil |
| 462 | } |
| 463 | lenJ := j.Len() |
| 464 | lenO := other.Len() |
| 465 | if lenJ < lenO { |
| 466 | return -1, nil |
| 467 | } |
| 468 | if lenJ > lenO { |
| 469 | return 1, nil |
| 470 | } |
| 471 | // TODO(justin): we should optimize this, we don't have to decode the whole thing. |
| 472 | var err error |
| 473 | if other, err = decodeIfNeeded(other); err != nil { |
| 474 | return 0, err |
| 475 | } |
| 476 | o := other.(jsonObject) |
| 477 | for i := 0; i < lenJ; i++ { |
| 478 | cmpKey, err := j[i].k.Compare(o[i].k) |
| 479 | if err != nil { |
| 480 | return 0, err |
| 481 | } |
| 482 | if cmpKey != 0 { |
| 483 | return cmpKey, nil |
| 484 | } |
| 485 | cmpVal, err := j[i].v.Compare(o[i].v) |
| 486 | if err != nil { |
| 487 | return 0, err |
| 488 | } |
| 489 | if cmpVal != 0 { |
| 490 | return cmpVal, nil |
| 491 | } |
| 492 | } |
| 493 | return 0, nil |
| 494 | } |
| 495 | |
| 496 | var errTrailingCharacters = pgerror.WithCandidateCode(errors.New("trailing characters after JSON document"), pgcode.InvalidTextRepresentation) |
| 497 |
nothing calls this directly
no test coverage detected