MCPcopy Index your code
hub / github.com/chainloop-dev/chainloop / Only

Method Only

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

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

(ctx context.Context)

Source from the content-addressed store, hash-verified

159// Returns a *NotSingularError when more than one User entity is found.
160// Returns a *NotFoundError when no User entities are found.
161func (_q *UserQuery) Only(ctx context.Context) (*User, 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{user.Label}
171 default:
172 return nil, &NotSingularError{user.Label}
173 }
174}
175
176// OnlyX is like Only, but panics if an error occurs.
177func (_q *UserQuery) OnlyX(ctx context.Context) *User {

Callers 15

OnlyXMethod · 0.95
CreateMethod · 0.45
GetOrgScopedMethod · 0.45
FindByIDMethod · 0.45
SaveMethod · 0.45
ReadMethod · 0.45
FindByIDInOrgMethod · 0.45
PendingInvitationMethod · 0.45
FindByIDMethod · 0.45
FindVersionByIDMethod · 0.45
DescribeMethod · 0.45
contractInOrgQueryFunction · 0.45

Calls 3

LimitMethod · 0.95
setContextOpFunction · 0.85
AllMethod · 0.45

Tested by

no test coverage detected