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

Method OnlyID

ent/share_query.go:184–198  ·  view source on GitHub ↗

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

(ctx context.Context)

Source from the content-addressed store, hash-verified

182// Returns a *NotSingularError when more than one Share ID is found.
183// Returns a *NotFoundError when no entities are found.
184func (sq *ShareQuery) OnlyID(ctx context.Context) (id int, err error) {
185 var ids []int
186 if ids, err = sq.Limit(2).IDs(setContextOp(ctx, sq.ctx, "OnlyID")); err != nil {
187 return
188 }
189 switch len(ids) {
190 case 1:
191 id = ids[0]
192 case 0:
193 err = &NotFoundError{share.Label}
194 default:
195 err = &NotSingularError{share.Label}
196 }
197 return
198}
199
200// OnlyIDX is like OnlyID, but panics if an error occurs.
201func (sq *ShareQuery) 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