Only returns a single Alert entity found by the query, ensuring it only returns one. Returns a *NotSingularError when more than one Alert entity is found. Returns a *NotFoundError when no Alert entities are found.
(ctx context.Context)
| 205 | // Returns a *NotSingularError when more than one Alert entity is found. |
| 206 | // Returns a *NotFoundError when no Alert entities are found. |
| 207 | func (_q *AlertQuery) Only(ctx context.Context) (*Alert, error) { |
| 208 | nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) |
| 209 | if err != nil { |
| 210 | return nil, err |
| 211 | } |
| 212 | switch len(nodes) { |
| 213 | case 1: |
| 214 | return nodes[0], nil |
| 215 | case 0: |
| 216 | return nil, &NotFoundError{alert.Label} |
| 217 | default: |
| 218 | return nil, &NotSingularError{alert.Label} |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | // OnlyX is like Only, but panics if an error occurs. |
| 223 | func (_q *AlertQuery) OnlyX(ctx context.Context) *Alert { |
no test coverage detected