MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / Exists

Method Exists

pkg/util/json/encoded.go:567–613  ·  view source on GitHub ↗
(key string)

Source from the content-addressed store, hash-verified

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