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)
| 232 | // Returns a *NotSingularError when more than one Alert ID is found. |
| 233 | // Returns a *NotFoundError when no entities are found. |
| 234 | func (_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. |
| 251 | func (_q *AlertQuery) OnlyIDX(ctx context.Context) int { |
no test coverage detected