MCPcopy
hub / github.com/crowdsecurity/crowdsec / Only

Method Only

pkg/database/ent/meta_query.go:133–146  ·  view source on GitHub ↗

Only returns a single Meta entity found by the query, ensuring it only returns one. Returns a *NotSingularError when more than one Meta entity is found. Returns a *NotFoundError when no Meta entities are found.

(ctx context.Context)

Source from the content-addressed store, hash-verified

131// Returns a *NotSingularError when more than one Meta entity is found.
132// Returns a *NotFoundError when no Meta entities are found.
133func (_q *MetaQuery) Only(ctx context.Context) (*Meta, error) {
134 nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
135 if err != nil {
136 return nil, err
137 }
138 switch len(nodes) {
139 case 1:
140 return nodes[0], nil
141 case 0:
142 return nil, &NotFoundError{meta.Label}
143 default:
144 return nil, &NotSingularError{meta.Label}
145 }
146}
147
148// OnlyX is like Only, but panics if an error occurs.
149func (_q *MetaQuery) OnlyX(ctx context.Context) *Meta {

Callers 15

OnlyXMethod · 0.95
DeleteAlertByIDMethod · 0.45
QueryMachineByIDMethod · 0.45
GetMethod · 0.45
GetMethod · 0.45
GetMethod · 0.45
GetMethod · 0.45
GetMethod · 0.45
GetMethod · 0.45
GetMethod · 0.45
GetMethod · 0.45
GetMethod · 0.45

Calls 3

LimitMethod · 0.95
setContextOpFunction · 0.85
AllMethod · 0.45

Tested by

no test coverage detected