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

Method Only

app/controlplane/pkg/data/ent/apitoken_query.go:184–197  ·  view source on GitHub ↗

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

(ctx context.Context)

Source from the content-addressed store, hash-verified

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

Callers 1

OnlyXMethod · 0.95

Calls 3

LimitMethod · 0.95
setContextOpFunction · 0.85
AllMethod · 0.45

Tested by

no test coverage detected