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

Method OnlyID

ent/entity_query.go:208–222  ·  view source on GitHub ↗

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

(ctx context.Context)

Source from the content-addressed store, hash-verified

206// Returns a *NotSingularError when more than one Entity ID is found.
207// Returns a *NotFoundError when no entities are found.
208func (eq *EntityQuery) OnlyID(ctx context.Context) (id int, err error) {
209 var ids []int
210 if ids, err = eq.Limit(2).IDs(setContextOp(ctx, eq.ctx, "OnlyID")); err != nil {
211 return
212 }
213 switch len(ids) {
214 case 1:
215 id = ids[0]
216 case 0:
217 err = &NotFoundError{entity.Label}
218 default:
219 err = &NotSingularError{entity.Label}
220 }
221 return
222}
223
224// OnlyIDX is like OnlyID, but panics if an error occurs.
225func (eq *EntityQuery) 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