MCPcopy Index your code
hub / github.com/cloudreve/cloudreve / OnlyID

Method OnlyID

ent/metadata_query.go:159–173  ·  view source on GitHub ↗

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

(ctx context.Context)

Source from the content-addressed store, hash-verified

157// Returns a *NotSingularError when more than one Metadata ID is found.
158// Returns a *NotFoundError when no entities are found.
159func (mq *MetadataQuery) OnlyID(ctx context.Context) (id int, err error) {
160 var ids []int
161 if ids, err = mq.Limit(2).IDs(setContextOp(ctx, mq.ctx, "OnlyID")); err != nil {
162 return
163 }
164 switch len(ids) {
165 case 1:
166 id = ids[0]
167 case 0:
168 err = &NotFoundError{metadata.Label}
169 default:
170 err = &NotSingularError{metadata.Label}
171 }
172 return
173}
174
175// OnlyIDX is like OnlyID, but panics if an error occurs.
176func (mq *MetadataQuery) 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