Bool returns a single bool from a selector. It is only allowed when selecting one field.
(ctx context.Context)
| 502 | |
| 503 | // Bool returns a single bool from a selector. It is only allowed when selecting one field. |
| 504 | func (s *selector) Bool(ctx context.Context) (_ bool, err error) { |
| 505 | var v []bool |
| 506 | if v, err = s.Bools(ctx); err != nil { |
| 507 | return |
| 508 | } |
| 509 | switch len(v) { |
| 510 | case 1: |
| 511 | return v[0], nil |
| 512 | case 0: |
| 513 | err = &NotFoundError{s.label} |
| 514 | default: |
| 515 | err = fmt.Errorf("ent: Bools returned %d results when one was expected", len(v)) |
| 516 | } |
| 517 | return |
| 518 | } |
| 519 | |
| 520 | // BoolX is like Bool, but panics if an error occurs. |
| 521 | func (s *selector) BoolX(ctx context.Context) bool { |
no test coverage detected