| 1 |
// Code generated by ent, DO NOT EDIT. |
| 2 |
|
| 3 |
package ent |
| 4 |
|
| 5 |
import ( |
| 6 |
"context" |
| 7 |
"fmt" |
| 8 |
"math" |
| 9 |
|
| 10 |
"entgo.io/ent" |
| 11 |
"entgo.io/ent/dialect/sql" |
| 12 |
"entgo.io/ent/dialect/sql/sqlgraph" |
| 13 |
"entgo.io/ent/schema/field" |
| 14 |
"github.com/google/uuid" |
| 15 |
"github.com/in-toto/archivista/ent/dsse" |
| 16 |
"github.com/in-toto/archivista/ent/payloaddigest" |
| 17 |
"github.com/in-toto/archivista/ent/predicate" |
| 18 |
) |
| 19 |
|
| 20 |
// PayloadDigestQuery is the builder for querying PayloadDigest entities. |
| 21 |
type PayloadDigestQuery struct { |
| 22 |
config |
| 23 |
ctx *QueryContext |
| 24 |
order []payloaddigest.OrderOption |
| 25 |
inters []Interceptor |
| 26 |
predicates []predicate.PayloadDigest |
| 27 |
withDsse *DsseQuery |
| 28 |
withFKs bool |
| 29 |
modifiers []func(*sql.Selector) |
| 30 |
loadTotal []func(context.Context, []*PayloadDigest) error |
| 31 |
// intermediate query (i.e. traversal path). |
| 32 |
sql *sql.Selector |
| 33 |
path func(context.Context) (*sql.Selector, error) |
| 34 |
} |
| 35 |
|
| 36 |
// Where adds a new predicate for the PayloadDigestQuery builder. |
| 37 |
func (_q *PayloadDigestQuery) Where(ps ...predicate.PayloadDigest) *PayloadDigestQuery { |
| 38 |
_q.predicates = append(_q.predicates, ps...) |
| 39 |
return _q |
| 40 |
} |
| 41 |
|
| 42 |
// Limit the number of records to be returned by this query. |
| 43 |
func (_q *PayloadDigestQuery) Limit(limit int) *PayloadDigestQuery { |
| 44 |
_q.ctx.Limit = &limit |
| 45 |
return _q |
| 46 |
} |
| 47 |
|
| 48 |
// Offset to start from. |
| 49 |
func (_q *PayloadDigestQuery) Offset(offset int) *PayloadDigestQuery { |
| 50 |
_q.ctx.Offset = &offset |
| 51 |
return _q |
| 52 |
} |
| 53 |
|
| 54 |
// Unique configures the query builder to filter duplicate records on query. |
| 55 |
// By default, unique is set to true, and can be disabled using this method. |
| 56 |
func (_q *PayloadDigestQuery) Unique(unique bool) *PayloadDigestQuery { |
| 57 |
_q.ctx.Unique = &unique |
| 58 |
return _q |
| 59 |
} |
| 60 |
|
| 61 |
// Order specifies how the records should be ordered. |
| 62 |
func (_q *PayloadDigestQuery) Order(o ...payloaddigest.OrderOption) *PayloadDigestQuery { |
| 63 |
_q.order = append(_q.order, o...) |
| 64 |
return _q |
| 65 |
} |
| 66 |
|
| 67 |
// QueryDsse chains the current query on the "dsse" edge. |
| 68 |
func (_q *PayloadDigestQuery) QueryDsse() *DsseQuery { |
| 69 |
query := (&DsseClient{config: _q.config}).Query() |
| 70 |
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { |
| 71 |
if err := _q.prepareQuery(ctx); err != nil { |
| 72 |
return nil, err |
| 73 |
} |
| 74 |
selector := _q.sqlQuery(ctx) |
| 75 |
if err := selector.Err(); err != nil { |
| 76 |
return nil, err |
| 77 |
} |
| 78 |
step := sqlgraph.NewStep( |
| 79 |
sqlgraph.From(payloaddigest.Table, payloaddigest.FieldID, selector), |
| 80 |
sqlgraph.To(dsse.Table, dsse.FieldID), |
| 81 |
sqlgraph.Edge(sqlgraph.M2O, true, payloaddigest.DsseTable, payloaddigest.DsseColumn), |
| 82 |
) |
| 83 |
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) |
| 84 |
return fromU, nil |
| 85 |
} |
| 86 |
return query |
| 87 |
} |
| 88 |
|
| 89 |
// First returns the first PayloadDigest entity from the query. |
| 90 |
// Returns a *NotFoundError when no PayloadDigest was found. |
| 91 |
func (_q *PayloadDigestQuery) First(ctx context.Context) (*PayloadDigest, error) { |
| 92 |
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) |
| 93 |
if err != nil { |
| 94 |
return nil, err |
| 95 |
} |
| 96 |
if len(nodes) == 0 { |
| 97 |
return nil, &NotFoundError{payloaddigest.Label} |
| 98 |
} |
| 99 |
return nodes[0], nil |
| 100 |
} |
| 101 |
|
| 102 |
// FirstX is like First, but panics if an error occurs. |
| 103 |
func (_q *PayloadDigestQuery) FirstX(ctx context.Context) *PayloadDigest { |
| 104 |
node, err := _q.First(ctx) |
| 105 |
if err != nil && !IsNotFound(err) { |
| 106 |
panic(err) |
| 107 |
} |
| 108 |
return node |
| 109 |
} |
| 110 |
|
| 111 |
// FirstID returns the first PayloadDigest ID from the query. |
| 112 |
// Returns a *NotFoundError when no PayloadDigest ID was found. |
| 113 |
func (_q *PayloadDigestQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { |
| 114 |
var ids []uuid.UUID |
| 115 |
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { |
| 116 |
return |
| 117 |
} |
| 118 |
if len(ids) == 0 { |
| 119 |
err = &NotFoundError{payloaddigest.Label} |
| 120 |
return |
| 121 |
} |
| 122 |
return ids[0], nil |
| 123 |
} |
| 124 |
|
| 125 |
// FirstIDX is like FirstID, but panics if an error occurs. |
| 126 |
func (_q *PayloadDigestQuery) FirstIDX(ctx context.Context) uuid.UUID { |
| 127 |
id, err := _q.FirstID(ctx) |
| 128 |
if err != nil && !IsNotFound(err) { |
| 129 |
panic(err) |
| 130 |
} |
| 131 |
return id |
| 132 |
} |
| 133 |
|
| 134 |
// Only returns a single PayloadDigest entity found by the query, ensuring it only returns one. |
| 135 |
// Returns a *NotSingularError when more than one PayloadDigest entity is found. |
| 136 |
// Returns a *NotFoundError when no PayloadDigest entities are found. |
| 137 |
func (_q *PayloadDigestQuery) Only(ctx context.Context) (*PayloadDigest, error) { |
| 138 |
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.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{payloaddigest.Label} |
| 147 |
default: |
| 148 |
return nil, &NotSingularError{payloaddigest.Label} |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
// OnlyX is like Only, but panics if an error occurs. |
| 153 |
func (_q *PayloadDigestQuery) OnlyX(ctx context.Context) *PayloadDigest { |
| 154 |
node, err := _q.Only(ctx) |
| 155 |
if err != nil { |
| 156 |
panic(err) |
| 157 |
} |
| 158 |
return node |
| 159 |
} |
| 160 |
|
| 161 |
// OnlyID is like Only, but returns the only PayloadDigest ID in the query. |
| 162 |
// Returns a *NotSingularError when more than one PayloadDigest ID is found. |
| 163 |
// Returns a *NotFoundError when no entities are found. |
| 164 |
func (_q *PayloadDigestQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { |
| 165 |
var ids []uuid.UUID |
| 166 |
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.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{payloaddigest.Label} |
| 174 |
default: |
| 175 |
err = &NotSingularError{payloaddigest.Label} |
| 176 |
} |
| 177 |
return |
| 178 |
} |
| 179 |
|
| 180 |
// OnlyIDX is like OnlyID, but panics if an error occurs. |
| 181 |
func (_q *PayloadDigestQuery) OnlyIDX(ctx context.Context) uuid.UUID { |
| 182 |
id, err := _q.OnlyID(ctx) |
| 183 |
if err != nil { |
| 184 |
panic(err) |
| 185 |
} |
| 186 |
return id |
| 187 |
} |
| 188 |
|
| 189 |
// All executes the query and returns a list of PayloadDigests. |
| 190 |
func (_q *PayloadDigestQuery) All(ctx context.Context) ([]*PayloadDigest, error) { |
| 191 |
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) |
| 192 |
if err := _q.prepareQuery(ctx); err != nil { |
| 193 |
return nil, err |
| 194 |
} |
| 195 |
qr := querierAll[[]*PayloadDigest, *PayloadDigestQuery]() |
| 196 |
return withInterceptors[[]*PayloadDigest](ctx, _q, qr, _q.inters) |
| 197 |
} |
| 198 |
|
| 199 |
// AllX is like All, but panics if an error occurs. |
| 200 |
func (_q *PayloadDigestQuery) AllX(ctx context.Context) []*PayloadDigest { |
| 201 |
nodes, err := _q.All(ctx) |
| 202 |
if err != nil { |
| 203 |
panic(err) |
| 204 |
} |
| 205 |
return nodes |
| 206 |
} |
| 207 |
|
| 208 |
// IDs executes the query and returns a list of PayloadDigest IDs. |
| 209 |
func (_q *PayloadDigestQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { |
| 210 |
if _q.ctx.Unique == nil && _q.path != nil { |
| 211 |
_q.Unique(true) |
| 212 |
} |
| 213 |
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) |
| 214 |
if err = _q.Select(payloaddigest.FieldID).Scan(ctx, &ids); err != nil { |
| 215 |
return nil, err |
| 216 |
} |
| 217 |
return ids, nil |
| 218 |
} |
| 219 |
|
| 220 |
// IDsX is like IDs, but panics if an error occurs. |
| 221 |
func (_q *PayloadDigestQuery) IDsX(ctx context.Context) []uuid.UUID { |
| 222 |
ids, err := _q.IDs(ctx) |
| 223 |
if err != nil { |
| 224 |
panic(err) |
| 225 |
} |
| 226 |
return ids |
| 227 |
} |
| 228 |
|
| 229 |
// Count returns the count of the given query. |
| 230 |
func (_q *PayloadDigestQuery) Count(ctx context.Context) (int, error) { |
| 231 |
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) |
| 232 |
if err := _q.prepareQuery(ctx); err != nil { |
| 233 |
return 0, err |
| 234 |
} |
| 235 |
return withInterceptors[int](ctx, _q, querierCount[*PayloadDigestQuery](), _q.inters) |
| 236 |
} |
| 237 |
|
| 238 |
// CountX is like Count, but panics if an error occurs. |
| 239 |
func (_q *PayloadDigestQuery) CountX(ctx context.Context) int { |
| 240 |
count, err := _q.Count(ctx) |
| 241 |
if err != nil { |
| 242 |
panic(err) |
| 243 |
} |
| 244 |
return count |
| 245 |
} |
| 246 |
|
| 247 |
// Exist returns true if the query has elements in the graph. |
| 248 |
func (_q *PayloadDigestQuery) Exist(ctx context.Context) (bool, error) { |
| 249 |
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) |
| 250 |
switch _, err := _q.FirstID(ctx); { |
| 251 |
case IsNotFound(err): |
| 252 |
return false, nil |
| 253 |
case err != nil: |
| 254 |
return false, fmt.Errorf("ent: check existence: %w", err) |
| 255 |
default: |
| 256 |
return true, nil |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
// ExistX is like Exist, but panics if an error occurs. |
| 261 |
func (_q *PayloadDigestQuery) ExistX(ctx context.Context) bool { |
| 262 |
exist, err := _q.Exist(ctx) |
| 263 |
if err != nil { |
| 264 |
panic(err) |
| 265 |
} |
| 266 |
return exist |
| 267 |
} |
| 268 |
|
| 269 |
// Clone returns a duplicate of the PayloadDigestQuery builder, including all associated steps. It can be |
| 270 |
// used to prepare common query builders and use them differently after the clone is made. |
| 271 |
func (_q *PayloadDigestQuery) Clone() *PayloadDigestQuery { |
| 272 |
if _q == nil { |
| 273 |
return nil |
| 274 |
} |
| 275 |
return &PayloadDigestQuery{ |
| 276 |
config: _q.config, |
| 277 |
ctx: _q.ctx.Clone(), |
| 278 |
order: append([]payloaddigest.OrderOption{}, _q.order...), |
| 279 |
inters: append([]Interceptor{}, _q.inters...), |
| 280 |
predicates: append([]predicate.PayloadDigest{}, _q.predicates...), |
| 281 |
withDsse: _q.withDsse.Clone(), |
| 282 |
// clone intermediate query. |
| 283 |
sql: _q.sql.Clone(), |
| 284 |
path: _q.path, |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
// WithDsse tells the query-builder to eager-load the nodes that are connected to |
| 289 |
// the "dsse" edge. The optional arguments are used to configure the query builder of the edge. |
| 290 |
func (_q *PayloadDigestQuery) WithDsse(opts ...func(*DsseQuery)) *PayloadDigestQuery { |
| 291 |
query := (&DsseClient{config: _q.config}).Query() |
| 292 |
for _, opt := range opts { |
| 293 |
opt(query) |
| 294 |
} |
| 295 |
_q.withDsse = query |
| 296 |
return _q |
| 297 |
} |
| 298 |
|
| 299 |
// GroupBy is used to group vertices by one or more fields/columns. |
| 300 |
// It is often used with aggregate functions, like: count, max, mean, min, sum. |
| 301 |
// |
| 302 |
// Example: |
| 303 |
// |
| 304 |
// var v []struct { |
| 305 |
// Algorithm string `json:"algorithm,omitempty"` |
| 306 |
// Count int `json:"count,omitempty"` |
| 307 |
// } |
| 308 |
// |
| 309 |
// client.PayloadDigest.Query(). |
| 310 |
// GroupBy(payloaddigest.FieldAlgorithm). |
| 311 |
// Aggregate(ent.Count()). |
| 312 |
// Scan(ctx, &v) |
| 313 |
func (_q *PayloadDigestQuery) GroupBy(field string, fields ...string) *PayloadDigestGroupBy { |
| 314 |
_q.ctx.Fields = append([]string{field}, fields...) |
| 315 |
grbuild := &PayloadDigestGroupBy{build: _q} |
| 316 |
grbuild.flds = &_q.ctx.Fields |
| 317 |
grbuild.label = payloaddigest.Label |
| 318 |
grbuild.scan = grbuild.Scan |
| 319 |
return grbuild |
| 320 |
} |
| 321 |
|
| 322 |
// Select allows the selection one or more fields/columns for the given query, |
| 323 |
// instead of selecting all fields in the entity. |
| 324 |
// |
| 325 |
// Example: |
| 326 |
// |
| 327 |
// var v []struct { |
| 328 |
// Algorithm string `json:"algorithm,omitempty"` |
| 329 |
// } |
| 330 |
// |
| 331 |
// client.PayloadDigest.Query(). |
| 332 |
// Select(payloaddigest.FieldAlgorithm). |
| 333 |
// Scan(ctx, &v) |
| 334 |
func (_q *PayloadDigestQuery) Select(fields ...string) *PayloadDigestSelect { |
| 335 |
_q.ctx.Fields = append(_q.ctx.Fields, fields...) |
| 336 |
sbuild := &PayloadDigestSelect{PayloadDigestQuery: _q} |
| 337 |
sbuild.label = payloaddigest.Label |
| 338 |
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan |
| 339 |
return sbuild |
| 340 |
} |
| 341 |
|
| 342 |
// Aggregate returns a PayloadDigestSelect configured with the given aggregations. |
| 343 |
func (_q *PayloadDigestQuery) Aggregate(fns ...AggregateFunc) *PayloadDigestSelect { |
| 344 |
return _q.Select().Aggregate(fns...) |
| 345 |
} |
| 346 |
|
| 347 |
func (_q *PayloadDigestQuery) prepareQuery(ctx context.Context) error { |
| 348 |
for _, inter := range _q.inters { |
| 349 |
if inter == nil { |
| 350 |
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") |
| 351 |
} |
| 352 |
if trv, ok := inter.(Traverser); ok { |
| 353 |
if err := trv.Traverse(ctx, _q); err != nil { |
| 354 |
return err |
| 355 |
} |
| 356 |
} |
| 357 |
} |
| 358 |
for _, f := range _q.ctx.Fields { |
| 359 |
if !payloaddigest.ValidColumn(f) { |
| 360 |
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} |
| 361 |
} |
| 362 |
} |
| 363 |
if _q.path != nil { |
| 364 |
prev, err := _q.path(ctx) |
| 365 |
if err != nil { |
| 366 |
return err |
| 367 |
} |
| 368 |
_q.sql = prev |
| 369 |
} |
| 370 |
return nil |
| 371 |
} |
| 372 |
|
| 373 |
func (_q *PayloadDigestQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*PayloadDigest, error) { |
| 374 |
var ( |
| 375 |
nodes = []*PayloadDigest{} |
| 376 |
withFKs = _q.withFKs |
| 377 |
_spec = _q.querySpec() |
| 378 |
loadedTypes = [1]bool{ |
| 379 |
_q.withDsse != nil, |
| 380 |
} |
| 381 |
) |
| 382 |
if _q.withDsse != nil { |
| 383 |
withFKs = true |
| 384 |
} |
| 385 |
if withFKs { |
| 386 |
_spec.Node.Columns = append(_spec.Node.Columns, payloaddigest.ForeignKeys...) |
| 387 |
} |
| 388 |
_spec.ScanValues = func(columns []string) ([]any, error) { |
| 389 |
return (*PayloadDigest).scanValues(nil, columns) |
| 390 |
} |
| 391 |
_spec.Assign = func(columns []string, values []any) error { |
| 392 |
node := &PayloadDigest{config: _q.config} |
| 393 |
nodes = append(nodes, node) |
| 394 |
node.Edges.loadedTypes = loadedTypes |
| 395 |
return node.assignValues(columns, values) |
| 396 |
} |
| 397 |
if len(_q.modifiers) > 0 { |
| 398 |
_spec.Modifiers = _q.modifiers |
| 399 |
} |
| 400 |
for i := range hooks { |
| 401 |
hooks[i](ctx, _spec) |
| 402 |
} |
| 403 |
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { |
| 404 |
return nil, err |
| 405 |
} |
| 406 |
if len(nodes) == 0 { |
| 407 |
return nodes, nil |
| 408 |
} |
| 409 |
if query := _q.withDsse; query != nil { |
| 410 |
if err := _q.loadDsse(ctx, query, nodes, nil, |
| 411 |
func(n *PayloadDigest, e *Dsse) { n.Edges.Dsse = e }); err != nil { |
| 412 |
return nil, err |
| 413 |
} |
| 414 |
} |
| 415 |
for i := range _q.loadTotal { |
| 416 |
if err := _q.loadTotal[i](ctx, nodes); err != nil { |
| 417 |
return nil, err |
| 418 |
} |
| 419 |
} |
| 420 |
return nodes, nil |
| 421 |
} |
| 422 |
|
| 423 |
func (_q *PayloadDigestQuery) loadDsse(ctx context.Context, query *DsseQuery, nodes []*PayloadDigest, init func(*PayloadDigest), assign func(*PayloadDigest, *Dsse)) error { |
| 424 |
ids := make([]uuid.UUID, 0, len(nodes)) |
| 425 |
nodeids := make(map[uuid.UUID][]*PayloadDigest) |
| 426 |
for i := range nodes { |
| 427 |
if nodes[i].dsse_payload_digests == nil { |
| 428 |
continue |
| 429 |
} |
| 430 |
fk := *nodes[i].dsse_payload_digests |
| 431 |
if _, ok := nodeids[fk]; !ok { |
| 432 |
ids = append(ids, fk) |
| 433 |
} |
| 434 |
nodeids[fk] = append(nodeids[fk], nodes[i]) |
| 435 |
} |
| 436 |
if len(ids) == 0 { |
| 437 |
return nil |
| 438 |
} |
| 439 |
query.Where(dsse.IDIn(ids...)) |
| 440 |
neighbors, err := query.All(ctx) |
| 441 |
if err != nil { |
| 442 |
return err |
| 443 |
} |
| 444 |
for _, n := range neighbors { |
| 445 |
nodes, ok := nodeids[n.ID] |
| 446 |
if !ok { |
| 447 |
return fmt.Errorf(`unexpected foreign-key "dsse_payload_digests" returned %v`, n.ID) |
| 448 |
} |
| 449 |
for i := range nodes { |
| 450 |
assign(nodes[i], n) |
| 451 |
} |
| 452 |
} |
| 453 |
return nil |
| 454 |
} |
| 455 |
|
| 456 |
func (_q *PayloadDigestQuery) sqlCount(ctx context.Context) (int, error) { |
| 457 |
_spec := _q.querySpec() |
| 458 |
if len(_q.modifiers) > 0 { |
| 459 |
_spec.Modifiers = _q.modifiers |
| 460 |
} |
| 461 |
_spec.Node.Columns = _q.ctx.Fields |
| 462 |
if len(_q.ctx.Fields) > 0 { |
| 463 |
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique |
| 464 |
} |
| 465 |
return sqlgraph.CountNodes(ctx, _q.driver, _spec) |
| 466 |
} |
| 467 |
|
| 468 |
func (_q *PayloadDigestQuery) querySpec() *sqlgraph.QuerySpec { |
| 469 |
_spec := sqlgraph.NewQuerySpec(payloaddigest.Table, payloaddigest.Columns, sqlgraph.NewFieldSpec(payloaddigest.FieldID, field.TypeUUID)) |
| 470 |
_spec.From = _q.sql |
| 471 |
if unique := _q.ctx.Unique; unique != nil { |
| 472 |
_spec.Unique = *unique |
| 473 |
} else if _q.path != nil { |
| 474 |
_spec.Unique = true |
| 475 |
} |
| 476 |
if fields := _q.ctx.Fields; len(fields) > 0 { |
| 477 |
_spec.Node.Columns = make([]string, 0, len(fields)) |
| 478 |
_spec.Node.Columns = append(_spec.Node.Columns, payloaddigest.FieldID) |
| 479 |
for i := range fields { |
| 480 |
if fields[i] != payloaddigest.FieldID { |
| 481 |
_spec.Node.Columns = append(_spec.Node.Columns, fields[i]) |
| 482 |
} |
| 483 |
} |
| 484 |
} |
| 485 |
if ps := _q.predicates; len(ps) > 0 { |
| 486 |
_spec.Predicate = func(selector *sql.Selector) { |
| 487 |
for i := range ps { |
| 488 |
ps[i](selector) |
| 489 |
} |
| 490 |
} |
| 491 |
} |
| 492 |
if limit := _q.ctx.Limit; limit != nil { |
| 493 |
_spec.Limit = *limit |
| 494 |
} |
| 495 |
if offset := _q.ctx.Offset; offset != nil { |
| 496 |
_spec.Offset = *offset |
| 497 |
} |
| 498 |
if ps := _q.order; len(ps) > 0 { |
| 499 |
_spec.Order = func(selector *sql.Selector) { |
| 500 |
for i := range ps { |
| 501 |
ps[i](selector) |
| 502 |
} |
| 503 |
} |
| 504 |
} |
| 505 |
return _spec |
| 506 |
} |
| 507 |
|
| 508 |
func (_q *PayloadDigestQuery) sqlQuery(ctx context.Context) *sql.Selector { |
| 509 |
builder := sql.Dialect(_q.driver.Dialect()) |
| 510 |
t1 := builder.Table(payloaddigest.Table) |
| 511 |
columns := _q.ctx.Fields |
| 512 |
if len(columns) == 0 { |
| 513 |
columns = payloaddigest.Columns |
| 514 |
} |
| 515 |
selector := builder.Select(t1.Columns(columns...)...).From(t1) |
| 516 |
if _q.sql != nil { |
| 517 |
selector = _q.sql |
| 518 |
selector.Select(selector.Columns(columns...)...) |
| 519 |
} |
| 520 |
if _q.ctx.Unique != nil && *_q.ctx.Unique { |
| 521 |
selector.Distinct() |
| 522 |
} |
| 523 |
for _, p := range _q.predicates { |
| 524 |
p(selector) |
| 525 |
} |
| 526 |
for _, p := range _q.order { |
| 527 |
p(selector) |
| 528 |
} |
| 529 |
if offset := _q.ctx.Offset; offset != nil { |
| 530 |
// limit is mandatory for offset clause. We start |
| 531 |
// with default value, and override it below if needed. |
| 532 |
selector.Offset(*offset).Limit(math.MaxInt32) |
| 533 |
} |
| 534 |
if limit := _q.ctx.Limit; limit != nil { |
| 535 |
selector.Limit(*limit) |
| 536 |
} |
| 537 |
return selector |
| 538 |
} |
| 539 |
|
| 540 |
// PayloadDigestGroupBy is the group-by builder for PayloadDigest entities. |
| 541 |
type PayloadDigestGroupBy struct { |
| 542 |
selector |
| 543 |
build *PayloadDigestQuery |
| 544 |
} |
| 545 |
|
| 546 |
// Aggregate adds the given aggregation functions to the group-by query. |
| 547 |
func (_g *PayloadDigestGroupBy) Aggregate(fns ...AggregateFunc) *PayloadDigestGroupBy { |
| 548 |
_g.fns = append(_g.fns, fns...) |
| 549 |
return _g |
| 550 |
} |
| 551 |
|
| 552 |
// Scan applies the selector query and scans the result into the given value. |
| 553 |
func (_g *PayloadDigestGroupBy) Scan(ctx context.Context, v any) error { |
| 554 |
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) |
| 555 |
if err := _g.build.prepareQuery(ctx); err != nil { |
| 556 |
return err |
| 557 |
} |
| 558 |
return scanWithInterceptors[*PayloadDigestQuery, *PayloadDigestGroupBy](ctx, _g.build, _g, _g.build.inters, v) |
| 559 |
} |
| 560 |
|
| 561 |
func (_g *PayloadDigestGroupBy) sqlScan(ctx context.Context, root *PayloadDigestQuery, v any) error { |
| 562 |
selector := root.sqlQuery(ctx).Select() |
| 563 |
aggregation := make([]string, 0, len(_g.fns)) |
| 564 |
for _, fn := range _g.fns { |
| 565 |
aggregation = append(aggregation, fn(selector)) |
| 566 |
} |
| 567 |
if len(selector.SelectedColumns()) == 0 { |
| 568 |
columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) |
| 569 |
for _, f := range *_g.flds { |
| 570 |
columns = append(columns, selector.C(f)) |
| 571 |
} |
| 572 |
columns = append(columns, aggregation...) |
| 573 |
selector.Select(columns...) |
| 574 |
} |
| 575 |
selector.GroupBy(selector.Columns(*_g.flds...)...) |
| 576 |
if err := selector.Err(); err != nil { |
| 577 |
return err |
| 578 |
} |
| 579 |
rows := &sql.Rows{} |
| 580 |
query, args := selector.Query() |
| 581 |
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { |
| 582 |
return err |
| 583 |
} |
| 584 |
defer rows.Close() |
| 585 |
return sql.ScanSlice(rows, v) |
| 586 |
} |
| 587 |
|
| 588 |
// PayloadDigestSelect is the builder for selecting fields of PayloadDigest entities. |
| 589 |
type PayloadDigestSelect struct { |
| 590 |
*PayloadDigestQuery |
| 591 |
selector |
| 592 |
} |
| 593 |
|
| 594 |
// Aggregate adds the given aggregation functions to the selector query. |
| 595 |
func (_s *PayloadDigestSelect) Aggregate(fns ...AggregateFunc) *PayloadDigestSelect { |
| 596 |
_s.fns = append(_s.fns, fns...) |
| 597 |
return _s |
| 598 |
} |
| 599 |
|
| 600 |
// Scan applies the selector query and scans the result into the given value. |
| 601 |
func (_s *PayloadDigestSelect) Scan(ctx context.Context, v any) error { |
| 602 |
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) |
| 603 |
if err := _s.prepareQuery(ctx); err != nil { |
| 604 |
return err |
| 605 |
} |
| 606 |
return scanWithInterceptors[*PayloadDigestQuery, *PayloadDigestSelect](ctx, _s.PayloadDigestQuery, _s, _s.inters, v) |
| 607 |
} |
| 608 |
|
| 609 |
func (_s *PayloadDigestSelect) sqlScan(ctx context.Context, root *PayloadDigestQuery, v any) error { |
| 610 |
selector := root.sqlQuery(ctx) |
| 611 |
aggregation := make([]string, 0, len(_s.fns)) |
| 612 |
for _, fn := range _s.fns { |
| 613 |
aggregation = append(aggregation, fn(selector)) |
| 614 |
} |
| 615 |
switch n := len(*_s.selector.flds); { |
| 616 |
case n == 0 && len(aggregation) > 0: |
| 617 |
selector.Select(aggregation...) |
| 618 |
case n != 0 && len(aggregation) > 0: |
| 619 |
selector.AppendSelect(aggregation...) |
| 620 |
} |
| 621 |
rows := &sql.Rows{} |
| 622 |
query, args := selector.Query() |
| 623 |
if err := _s.driver.Query(ctx, query, args, rows); err != nil { |
| 624 |
return err |
| 625 |
} |
| 626 |
defer rows.Close() |
| 627 |
return sql.ScanSlice(rows, v) |
| 628 |
} |