OnlyID is like Only, but returns the only GitCommit ID in the query. Returns a *NotSingularError when more than one GitCommit ID is found. Returns a *NotFoundError when no entities are found.
(ctx context.Context)
| 162 | // Returns a *NotSingularError when more than one GitCommit ID is found. |
| 163 | // Returns a *NotFoundError when no entities are found. |
| 164 | func (gcq *GitCommitQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { |
| 165 | var ids []uuid.UUID |
| 166 | if ids, err = gcq.Limit(2).IDs(setContextOp(ctx, gcq.ctx, ent.OpQueryOnlyID)); err != nil { |
| 167 | return |
| 168 | } |
| 169 | switch len(ids) { |
| 170 | case 1: |
| 171 | id = ids[0] |
| 172 | case 0: |
| 173 | err = &NotFoundError{gitcommit.Label} |
| 174 | default: |
| 175 | err = &NotSingularError{gitcommit.Label} |
| 176 | } |
| 177 | return |
| 178 | } |
| 179 | |
| 180 | // OnlyIDX is like OnlyID, but panics if an error occurs. |
| 181 | func (gcq *GitCommitQuery) OnlyIDX(ctx context.Context) uuid.UUID { |
no test coverage detected