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

Method OnlyID

pkg/database/ent/meta_query.go:160–174  ·  view source on GitHub ↗

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