Int returns a single int from a selector. It is only allowed when selecting one field.
(ctx context.Context)
| 408 | |
| 409 | // Int returns a single int from a selector. It is only allowed when selecting one field. |
| 410 | func (s *selector) Int(ctx context.Context) (_ int, err error) { |
| 411 | var v []int |
| 412 | if v, err = s.Ints(ctx); err != nil { |
| 413 | return |
| 414 | } |
| 415 | switch len(v) { |
| 416 | case 1: |
| 417 | return v[0], nil |
| 418 | case 0: |
| 419 | err = &NotFoundError{s.label} |
| 420 | default: |
| 421 | err = fmt.Errorf("ent: Ints returned %d results when one was expected", len(v)) |
| 422 | } |
| 423 | return |
| 424 | } |
| 425 | |
| 426 | // IntX is like Int, but panics if an error occurs. |
| 427 | func (s *selector) IntX(ctx context.Context) int { |
no test coverage detected