MCPcopy Create free account
hub / github.com/dolthub/doltgresql / Exists

Method Exists

postgres/parser/json/encoded.go:581–627  ·  view source on GitHub ↗
(key string)

Source from the content-addressed store, hash-verified

579}
580
581func (j *jsonEncoded) Exists(key string) (bool, error) {
582 if dec := j.alreadyDecoded(); dec != nil {
583 return dec.Exists(key)
584 }
585
586 switch j.typ {
587 case ObjectJSONType:
588 v, err := j.FetchValKey(key)
589 if err != nil {
590 return false, err
591 }
592 return v != nil, nil
593 case ArrayJSONType:
594 iter := j.iterArrayValues()
595 for {
596 nextJEntry, data, ok, err := iter.nextEncoded()
597 if err != nil {
598 return false, err
599 }
600 if !ok {
601 return false, nil
602 }
603 next, err := newEncoded(nextJEntry, data)
604 if err != nil {
605 return false, err
606 }
607 // This is a minor optimization - we know that newEncoded always returns a
608 // jsonEncoded if it's decoding a string, and we can save actually
609 // allocating that string for this check by not forcing a decode into a
610 // jsonString. This operates on two major assumptions:
611 // 1. newEncoded returns a jsonEncoded (and not a jsonString) for string
612 // types and
613 // 2. the `value` field on such a jsonEncoded directly corresponds to the string.
614 // This is tested sufficiently that if either of those assumptions is
615 // broken it will be caught.
616 if next.Type() == StringJSONType && string(next.(*jsonEncoded).value) == key {
617 return true, nil
618 }
619 }
620 default:
621 s, err := j.decode()
622 if err != nil {
623 return false, err
624 }
625 return s.Exists(key)
626 }
627}
628
629func (j *jsonEncoded) FetchValKeyOrIdx(key string) (JSON, error) {
630 switch j.typ {

Callers

nothing calls this directly

Calls 8

alreadyDecodedMethod · 0.95
FetchValKeyMethod · 0.95
iterArrayValuesMethod · 0.95
decodeMethod · 0.95
newEncodedFunction · 0.85
ExistsMethod · 0.65
TypeMethod · 0.65
nextEncodedMethod · 0.45

Tested by

no test coverage detected