Only returns a single APIToken entity found by the query, ensuring it only returns one. Returns a *NotSingularError when more than one APIToken entity is found. Returns a *NotFoundError when no APIToken entities are found.
(ctx context.Context)
| 182 | // Returns a *NotSingularError when more than one APIToken entity is found. |
| 183 | // Returns a *NotFoundError when no APIToken entities are found. |
| 184 | func (_q *APITokenQuery) Only(ctx context.Context) (*APIToken, error) { |
| 185 | nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) |
| 186 | if err != nil { |
| 187 | return nil, err |
| 188 | } |
| 189 | switch len(nodes) { |
| 190 | case 1: |
| 191 | return nodes[0], nil |
| 192 | case 0: |
| 193 | return nil, &NotFoundError{apitoken.Label} |
| 194 | default: |
| 195 | return nil, &NotSingularError{apitoken.Label} |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | // OnlyX is like Only, but panics if an error occurs. |
| 200 | func (_q *APITokenQuery) OnlyX(ctx context.Context) *APIToken { |
no test coverage detected