MCPcopy Create free account
hub / github.com/crowdsecurity/crowdsec / OnlyID

Method OnlyID

pkg/database/ent/machine_query.go:161–175  ·  view source on GitHub ↗

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

(ctx context.Context)

Source from the content-addressed store, hash-verified

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