MCPcopy Create free account
hub / github.com/cloudreve/cloudreve / OnlyID

Method OnlyID

ent/user_query.go:352–366  ·  view source on GitHub ↗

OnlyID is like Only, but returns the only User ID in the query. Returns a *NotSingularError when more than one User ID is found. Returns a *NotFoundError when no entities are found.

(ctx context.Context)

Source from the content-addressed store, hash-verified

350// Returns a *NotSingularError when more than one User ID is found.
351// Returns a *NotFoundError when no entities are found.
352func (uq *UserQuery) OnlyID(ctx context.Context) (id int, err error) {
353 var ids []int
354 if ids, err = uq.Limit(2).IDs(setContextOp(ctx, uq.ctx, "OnlyID")); err != nil {
355 return
356 }
357 switch len(ids) {
358 case 1:
359 id = ids[0]
360 case 0:
361 err = &NotFoundError{user.Label}
362 default:
363 err = &NotSingularError{user.Label}
364 }
365 return
366}
367
368// OnlyIDX is like OnlyID, but panics if an error occurs.
369func (uq *UserQuery) OnlyIDX(ctx context.Context) int {

Callers 1

OnlyIDXMethod · 0.95

Calls 3

LimitMethod · 0.95
setContextOpFunction · 0.85
IDsMethod · 0.45

Tested by

no test coverage detected