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

Method OnlyID

ent/node_query.go:160–174  ·  view source on GitHub ↗

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

(ctx context.Context)

Source from the content-addressed store, hash-verified

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