OnlyID is like Only, but returns the only Share ID in the query. Returns a *NotSingularError when more than one Share ID is found. Returns a *NotFoundError when no entities are found.
(ctx context.Context)
| 182 | // Returns a *NotSingularError when more than one Share ID is found. |
| 183 | // Returns a *NotFoundError when no entities are found. |
| 184 | func (sq *ShareQuery) OnlyID(ctx context.Context) (id int, err error) { |
| 185 | var ids []int |
| 186 | if ids, err = sq.Limit(2).IDs(setContextOp(ctx, sq.ctx, "OnlyID")); err != nil { |
| 187 | return |
| 188 | } |
| 189 | switch len(ids) { |
| 190 | case 1: |
| 191 | id = ids[0] |
| 192 | case 0: |
| 193 | err = &NotFoundError{share.Label} |
| 194 | default: |
| 195 | err = &NotSingularError{share.Label} |
| 196 | } |
| 197 | return |
| 198 | } |
| 199 | |
| 200 | // OnlyIDX is like OnlyID, but panics if an error occurs. |
| 201 | func (sq *ShareQuery) OnlyIDX(ctx context.Context) int { |
no test coverage detected