OnlyID is like Only, but returns the only User ID in the query. Returns a *NotSingularError when more than one User ID is found. Returns a *NotFoundError when no entities are found.
(ctx context.Context)
| 350 | // Returns a *NotSingularError when more than one User ID is found. |
| 351 | // Returns a *NotFoundError when no entities are found. |
| 352 | func (uq *UserQuery) OnlyID(ctx context.Context) (id int, err error) { |
| 353 | var ids []int |
| 354 | if ids, err = uq.Limit(2).IDs(setContextOp(ctx, uq.ctx, "OnlyID")); err != nil { |
| 355 | return |
| 356 | } |
| 357 | switch len(ids) { |
| 358 | case 1: |
| 359 | id = ids[0] |
| 360 | case 0: |
| 361 | err = &NotFoundError{user.Label} |
| 362 | default: |
| 363 | err = &NotSingularError{user.Label} |
| 364 | } |
| 365 | return |
| 366 | } |
| 367 | |
| 368 | // OnlyIDX is like OnlyID, but panics if an error occurs. |
| 369 | func (uq *UserQuery) OnlyIDX(ctx context.Context) int { |
no test coverage detected