Only returns a single GitCommit entity found by the query, ensuring it only returns one. Returns a *NotSingularError when more than one GitCommit entity is found. Returns a *NotFoundError when no GitCommit entities are found.
(ctx context.Context)
| 135 | // Returns a *NotSingularError when more than one GitCommit entity is found. |
| 136 | // Returns a *NotFoundError when no GitCommit entities are found. |
| 137 | func (gcq *GitCommitQuery) Only(ctx context.Context) (*GitCommit, error) { |
| 138 | nodes, err := gcq.Limit(2).All(setContextOp(ctx, gcq.ctx, ent.OpQueryOnly)) |
| 139 | if err != nil { |
| 140 | return nil, err |
| 141 | } |
| 142 | switch len(nodes) { |
| 143 | case 1: |
| 144 | return nodes[0], nil |
| 145 | case 0: |
| 146 | return nil, &NotFoundError{gitcommit.Label} |
| 147 | default: |
| 148 | return nil, &NotSingularError{gitcommit.Label} |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // OnlyX is like Only, but panics if an error occurs. |
| 153 | func (gcq *GitCommitQuery) OnlyX(ctx context.Context) *GitCommit { |
no test coverage detected