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

Method OnlyID

pkg/database/ent/alert_query.go:234–248  ·  view source on GitHub ↗

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

(ctx context.Context)

Source from the content-addressed store, hash-verified

232// Returns a *NotSingularError when more than one Alert ID is found.
233// Returns a *NotFoundError when no entities are found.
234func (_q *AlertQuery) OnlyID(ctx context.Context) (id int, err error) {
235 var ids []int
236 if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
237 return
238 }
239 switch len(ids) {
240 case 1:
241 id = ids[0]
242 case 0:
243 err = &NotFoundError{alert.Label}
244 default:
245 err = &NotSingularError{alert.Label}
246 }
247 return
248}
249
250// OnlyIDX is like OnlyID, but panics if an error occurs.
251func (_q *AlertQuery) 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