(path []string)
| 1713 | } |
| 1714 | |
| 1715 | func (j jsonArray) doRemovePath(path []string) (JSON, bool, error) { |
| 1716 | if len(path) == 0 { |
| 1717 | return j, false, nil |
| 1718 | } |
| 1719 | // In path-deletion we have to attempt to parse numbers (this is different |
| 1720 | // from the `-` operator, where strings just never match on arrays). |
| 1721 | idx, err := strconv.Atoi(path[0]) |
| 1722 | if err != nil { |
| 1723 | // TODO(yuzefovich): give the position of the path element to match psql. |
| 1724 | err := errors.Newf("a path element is not an integer: %s", path[0]) |
| 1725 | err = pgerror.WithCandidateCode(err, pgcode.InvalidTextRepresentation) |
| 1726 | return j, false, err |
| 1727 | } |
| 1728 | if len(path) == 1 { |
| 1729 | return j.RemoveIndex(idx) |
| 1730 | } |
| 1731 | |
| 1732 | if idx < -len(j) || idx >= len(j) { |
| 1733 | return j, false, nil |
| 1734 | } |
| 1735 | if idx < 0 { |
| 1736 | idx += len(j) |
| 1737 | } |
| 1738 | newVal, ok, err := j[idx].doRemovePath(path[1:]) |
| 1739 | if err != nil { |
| 1740 | return nil, false, err |
| 1741 | } |
| 1742 | if !ok { |
| 1743 | return j, false, nil |
| 1744 | } |
| 1745 | |
| 1746 | result := make(jsonArray, len(j)) |
| 1747 | for i := range j { |
| 1748 | result[i] = j[i] |
| 1749 | } |
| 1750 | result[idx] = newVal |
| 1751 | |
| 1752 | return result, true, nil |
| 1753 | } |
| 1754 | |
| 1755 | func (j jsonObject) doRemovePath(path []string) (JSON, bool, error) { |
| 1756 | if len(path) == 0 { |
no test coverage detected