MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / Only

Method Only

app/controlplane/pkg/data/ent/referrer_query.go:183–196  ·  view source on GitHub ↗

Only returns a single Referrer entity found by the query, ensuring it only returns one. Returns a *NotSingularError when more than one Referrer entity is found. Returns a *NotFoundError when no Referrer entities are found.

(ctx context.Context)

Source from the content-addressed store, hash-verified

181// Returns a *NotSingularError when more than one Referrer entity is found.
182// Returns a *NotFoundError when no Referrer entities are found.
183func (_q *ReferrerQuery) Only(ctx context.Context) (*Referrer, error) {
184 nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
185 if err != nil {
186 return nil, err
187 }
188 switch len(nodes) {
189 case 1:
190 return nodes[0], nil
191 case 0:
192 return nil, &NotFoundError{referrer.Label}
193 default:
194 return nil, &NotSingularError{referrer.Label}
195 }
196}
197
198// OnlyX is like Only, but panics if an error occurs.
199func (_q *ReferrerQuery) OnlyX(ctx context.Context) *Referrer {

Callers 1

OnlyXMethod · 0.95

Calls 3

LimitMethod · 0.95
setContextOpFunction · 0.85
AllMethod · 0.45

Tested by

no test coverage detected