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)
| 209 | // Returns a *NotSingularError when more than one Node ID is found. |
| 210 | // Returns a *NotFoundError when no entities are found. |
| 211 | func (nq *NodeQuery) OnlyID(ctx context.Context) (id string, err error) { |
| 212 | var ids []string |
| 213 | if ids, err = nq.Limit(2).IDs(setContextOp(ctx, nq.ctx, ent.OpQueryOnlyID)); err != nil { |
| 214 | return |
| 215 | } |
| 216 | switch len(ids) { |
| 217 | case 1: |
| 218 | id = ids[0] |
| 219 | case 0: |
| 220 | err = &NotFoundError{node.Label} |
| 221 | default: |
| 222 | err = &NotSingularError{node.Label} |
| 223 | } |
| 224 | return |
| 225 | } |
| 226 | |
| 227 | // OnlyIDX is like OnlyID, but panics if an error occurs. |
| 228 | func (nq *NodeQuery) OnlyIDX(ctx context.Context) string { |
no test coverage detected