OnlyID is like Only, but returns the only Node ID in the query. Returns a *NotSingularError when more than one Node ID is found. Returns a *NotFoundError when no entities are found.
(ctx context.Context)
| 158 | // Returns a *NotSingularError when more than one Node ID is found. |
| 159 | // Returns a *NotFoundError when no entities are found. |
| 160 | func (nq *NodeQuery) OnlyID(ctx context.Context) (id int, err error) { |
| 161 | var ids []int |
| 162 | if ids, err = nq.Limit(2).IDs(setContextOp(ctx, nq.ctx, "OnlyID")); err != nil { |
| 163 | return |
| 164 | } |
| 165 | switch len(ids) { |
| 166 | case 1: |
| 167 | id = ids[0] |
| 168 | case 0: |
| 169 | err = &NotFoundError{node.Label} |
| 170 | default: |
| 171 | err = &NotSingularError{node.Label} |
| 172 | } |
| 173 | return |
| 174 | } |
| 175 | |
| 176 | // OnlyIDX is like OnlyID, but panics if an error occurs. |
| 177 | func (nq *NodeQuery) OnlyIDX(ctx context.Context) int { |
no test coverage detected