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

Method Only

app/controlplane/pkg/data/ent/group_query.go:161–174  ·  view source on GitHub ↗

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

(ctx context.Context)

Source from the content-addressed store, hash-verified

159// Returns a *NotSingularError when more than one Group entity is found.
160// Returns a *NotFoundError when no Group entities are found.
161func (_q *GroupQuery) Only(ctx context.Context) (*Group, error) {
162 nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
163 if err != nil {
164 return nil, err
165 }
166 switch len(nodes) {
167 case 1:
168 return nodes[0], nil
169 case 0:
170 return nil, &NotFoundError{group.Label}
171 default:
172 return nil, &NotSingularError{group.Label}
173 }
174}
175
176// OnlyX is like Only, but panics if an error occurs.
177func (_q *GroupQuery) OnlyX(ctx context.Context) *Group {

Callers 1

OnlyXMethod · 0.95

Calls 3

LimitMethod · 0.95
setContextOpFunction · 0.85
AllMethod · 0.45

Tested by

no test coverage detected