| 1 |
// Code generated by ent, DO NOT EDIT. |
| 2 |
|
| 3 |
package ent |
| 4 |
|
| 5 |
import ( |
| 6 |
"context" |
| 7 |
"database/sql/driver" |
| 8 |
"fmt" |
| 9 |
"math" |
| 10 |
|
| 11 |
"entgo.io/ent" |
| 12 |
"entgo.io/ent/dialect/sql" |
| 13 |
"entgo.io/ent/dialect/sql/sqlgraph" |
| 14 |
"entgo.io/ent/schema/field" |
| 15 |
"github.com/google/uuid" |
| 16 |
"github.com/in-toto/archivista/ent/dsse" |
| 17 |
"github.com/in-toto/archivista/ent/payloaddigest" |
| 18 |
"github.com/in-toto/archivista/ent/predicate" |
| 19 |
"github.com/in-toto/archivista/ent/signature" |
| 20 |
"github.com/in-toto/archivista/ent/statement" |
| 21 |
) |
| 22 |
|
| 23 |
// DsseQuery is the builder for querying Dsse entities. |
| 24 |
type DsseQuery struct { |
| 25 |
config |
| 26 |
ctx *QueryContext |
| 27 |
order []dsse.OrderOption |
| 28 |
inters []Interceptor |
| 29 |
predicates []predicate.Dsse |
| 30 |
withStatement *StatementQuery |
| 31 |
withSignatures *SignatureQuery |
| 32 |
withPayloadDigests *PayloadDigestQuery |
| 33 |
withFKs bool |
| 34 |
modifiers []func(*sql.Selector) |
| 35 |
loadTotal []func(context.Context, []*Dsse) error |
| 36 |
withNamedSignatures map[string]*SignatureQuery |
| 37 |
withNamedPayloadDigests map[string]*PayloadDigestQuery |
| 38 |
// intermediate query (i.e. traversal path). |
| 39 |
sql *sql.Selector |
| 40 |
path func(context.Context) (*sql.Selector, error) |
| 41 |
} |
| 42 |
|
| 43 |
// Where adds a new predicate for the DsseQuery builder. |
| 44 |
func (_q *DsseQuery) Where(ps ...predicate.Dsse) *DsseQuery { |
| 45 |
_q.predicates = append(_q.predicates, ps...) |
| 46 |
return _q |
| 47 |
} |
| 48 |
|
| 49 |
// Limit the number of records to be returned by this query. |
| 50 |
func (_q *DsseQuery) Limit(limit int) *DsseQuery { |
| 51 |
_q.ctx.Limit = &limit |
| 52 |
return _q |
| 53 |
} |
| 54 |
|
| 55 |
// Offset to start from. |
| 56 |
func (_q *DsseQuery) Offset(offset int) *DsseQuery { |
| 57 |
_q.ctx.Offset = &offset |
| 58 |
return _q |
| 59 |
} |
| 60 |
|
| 61 |
// Unique configures the query builder to filter duplicate records on query. |
| 62 |
// By default, unique is set to true, and can be disabled using this method. |
| 63 |
func (_q *DsseQuery) Unique(unique bool) *DsseQuery { |
| 64 |
_q.ctx.Unique = &unique |
| 65 |
return _q |
| 66 |
} |
| 67 |
|
| 68 |
// Order specifies how the records should be ordered. |
| 69 |
func (_q *DsseQuery) Order(o ...dsse.OrderOption) *DsseQuery { |
| 70 |
_q.order = append(_q.order, o...) |
| 71 |
return _q |
| 72 |
} |
| 73 |
|
| 74 |
// QueryStatement chains the current query on the "statement" edge. |
| 75 |
func (_q *DsseQuery) QueryStatement() *StatementQuery { |
| 76 |
query := (&StatementClient{config: _q.config}).Query() |
| 77 |
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { |
| 78 |
if err := _q.prepareQuery(ctx); err != nil { |
| 79 |
return nil, err |
| 80 |
} |
| 81 |
selector := _q.sqlQuery(ctx) |
| 82 |
if err := selector.Err(); err != nil { |
| 83 |
return nil, err |
| 84 |
} |
| 85 |
step := sqlgraph.NewStep( |
| 86 |
sqlgraph.From(dsse.Table, dsse.FieldID, selector), |
| 87 |
sqlgraph.To(statement.Table, statement.FieldID), |
| 88 |
sqlgraph.Edge(sqlgraph.M2O, false, dsse.StatementTable, dsse.StatementColumn), |
| 89 |
) |
| 90 |
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) |
| 91 |
return fromU, nil |
| 92 |
} |
| 93 |
return query |
| 94 |
} |
| 95 |
|
| 96 |
// QuerySignatures chains the current query on the "signatures" edge. |
| 97 |
func (_q *DsseQuery) QuerySignatures() *SignatureQuery { |
| 98 |
query := (&SignatureClient{config: _q.config}).Query() |
| 99 |
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { |
| 100 |
if err := _q.prepareQuery(ctx); err != nil { |
| 101 |
return nil, err |
| 102 |
} |
| 103 |
selector := _q.sqlQuery(ctx) |
| 104 |
if err := selector.Err(); err != nil { |
| 105 |
return nil, err |
| 106 |
} |
| 107 |
step := sqlgraph.NewStep( |
| 108 |
sqlgraph.From(dsse.Table, dsse.FieldID, selector), |
| 109 |
sqlgraph.To(signature.Table, signature.FieldID), |
| 110 |
sqlgraph.Edge(sqlgraph.O2M, false, dsse.SignaturesTable, dsse.SignaturesColumn), |
| 111 |
) |
| 112 |
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) |
| 113 |
return fromU, nil |
| 114 |
} |
| 115 |
return query |
| 116 |
} |
| 117 |
|
| 118 |
// QueryPayloadDigests chains the current query on the "payload_digests" edge. |
| 119 |
func (_q *DsseQuery) QueryPayloadDigests() *PayloadDigestQuery { |
| 120 |
query := (&PayloadDigestClient{config: _q.config}).Query() |
| 121 |
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { |
| 122 |
if err := _q.prepareQuery(ctx); err != nil { |
| 123 |
return nil, err |
| 124 |
} |
| 125 |
selector := _q.sqlQuery(ctx) |
| 126 |
if err := selector.Err(); err != nil { |
| 127 |
return nil, err |
| 128 |
} |
| 129 |
step := sqlgraph.NewStep( |
| 130 |
sqlgraph.From(dsse.Table, dsse.FieldID, selector), |
| 131 |
sqlgraph.To(payloaddigest.Table, payloaddigest.FieldID), |
| 132 |
sqlgraph.Edge(sqlgraph.O2M, false, dsse.PayloadDigestsTable, dsse.PayloadDigestsColumn), |
| 133 |
) |
| 134 |
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) |
| 135 |
return fromU, nil |
| 136 |
} |
| 137 |
return query |
| 138 |
} |
| 139 |
|
| 140 |
// First returns the first Dsse entity from the query. |
| 141 |
// Returns a *NotFoundError when no Dsse was found. |
| 142 |
func (_q *DsseQuery) First(ctx context.Context) (*Dsse, error) { |
| 143 |
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) |
| 144 |
if err != nil { |
| 145 |
return nil, err |
| 146 |
} |
| 147 |
if len(nodes) == 0 { |
| 148 |
return nil, &NotFoundError{dsse.Label} |
| 149 |
} |
| 150 |
return nodes[0], nil |
| 151 |
} |
| 152 |
|
| 153 |
// FirstX is like First, but panics if an error occurs. |
| 154 |
func (_q *DsseQuery) FirstX(ctx context.Context) *Dsse { |
| 155 |
node, err := _q.First(ctx) |
| 156 |
if err != nil && !IsNotFound(err) { |
| 157 |
panic(err) |
| 158 |
} |
| 159 |
return node |
| 160 |
} |
| 161 |
|
| 162 |
// FirstID returns the first Dsse ID from the query. |
| 163 |
// Returns a *NotFoundError when no Dsse ID was found. |
| 164 |
func (_q *DsseQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { |
| 165 |
var ids []uuid.UUID |
| 166 |
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { |
| 167 |
return |
| 168 |
} |
| 169 |
if len(ids) == 0 { |
| 170 |
err = &NotFoundError{dsse.Label} |
| 171 |
return |
| 172 |
} |
| 173 |
return ids[0], nil |
| 174 |
} |
| 175 |
|
| 176 |
// FirstIDX is like FirstID, but panics if an error occurs. |
| 177 |
func (_q *DsseQuery) FirstIDX(ctx context.Context) uuid.UUID { |
| 178 |
id, err := _q.FirstID(ctx) |
| 179 |
if err != nil && !IsNotFound(err) { |
| 180 |
panic(err) |
| 181 |
} |
| 182 |
return id |
| 183 |
} |
| 184 |
|
| 185 |
// Only returns a single Dsse entity found by the query, ensuring it only returns one. |
| 186 |
// Returns a *NotSingularError when more than one Dsse entity is found. |
| 187 |
// Returns a *NotFoundError when no Dsse entities are found. |
| 188 |
func (_q *DsseQuery) Only(ctx context.Context) (*Dsse, error) { |
| 189 |
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) |
| 190 |
if err != nil { |
| 191 |
return nil, err |
| 192 |
} |
| 193 |
switch len(nodes) { |
| 194 |
case 1: |
| 195 |
return nodes[0], nil |
| 196 |
case 0: |
| 197 |
return nil, &NotFoundError{dsse.Label} |
| 198 |
default: |
| 199 |
return nil, &NotSingularError{dsse.Label} |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
// OnlyX is like Only, but panics if an error occurs. |
| 204 |
func (_q *DsseQuery) OnlyX(ctx context.Context) *Dsse { |
| 205 |
node, err := _q.Only(ctx) |
| 206 |
if err != nil { |
| 207 |
panic(err) |
| 208 |
} |
| 209 |
return node |
| 210 |
} |
| 211 |
|
| 212 |
// OnlyID is like Only, but returns the only Dsse ID in the query. |
| 213 |
// Returns a *NotSingularError when more than one Dsse ID is found. |
| 214 |
// Returns a *NotFoundError when no entities are found. |
| 215 |
func (_q *DsseQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { |
| 216 |
var ids []uuid.UUID |
| 217 |
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { |
| 218 |
return |
| 219 |
} |
| 220 |
switch len(ids) { |
| 221 |
case 1: |
| 222 |
id = ids[0] |
| 223 |
case 0: |
| 224 |
err = &NotFoundError{dsse.Label} |
| 225 |
default: |
| 226 |
err = &NotSingularError{dsse.Label} |
| 227 |
} |
| 228 |
return |
| 229 |
} |
| 230 |
|
| 231 |
// OnlyIDX is like OnlyID, but panics if an error occurs. |
| 232 |
func (_q *DsseQuery) OnlyIDX(ctx context.Context) uuid.UUID { |
| 233 |
id, err := _q.OnlyID(ctx) |
| 234 |
if err != nil { |
| 235 |
panic(err) |
| 236 |
} |
| 237 |
return id |
| 238 |
} |
| 239 |
|
| 240 |
// All executes the query and returns a list of Dsses. |
| 241 |
func (_q *DsseQuery) All(ctx context.Context) ([]*Dsse, error) { |
| 242 |
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) |
| 243 |
if err := _q.prepareQuery(ctx); err != nil { |
| 244 |
return nil, err |
| 245 |
} |
| 246 |
qr := querierAll[[]*Dsse, *DsseQuery]() |
| 247 |
return withInterceptors[[]*Dsse](ctx, _q, qr, _q.inters) |
| 248 |
} |
| 249 |
|
| 250 |
// AllX is like All, but panics if an error occurs. |
| 251 |
func (_q *DsseQuery) AllX(ctx context.Context) []*Dsse { |
| 252 |
nodes, err := _q.All(ctx) |
| 253 |
if err != nil { |
| 254 |
panic(err) |
| 255 |
} |
| 256 |
return nodes |
| 257 |
} |
| 258 |
|
| 259 |
// IDs executes the query and returns a list of Dsse IDs. |
| 260 |
func (_q *DsseQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { |
| 261 |
if _q.ctx.Unique == nil && _q.path != nil { |
| 262 |
_q.Unique(true) |
| 263 |
} |
| 264 |
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) |
| 265 |
if err = _q.Select(dsse.FieldID).Scan(ctx, &ids); err != nil { |
| 266 |
return nil, err |
| 267 |
} |
| 268 |
return ids, nil |
| 269 |
} |
| 270 |
|
| 271 |
// IDsX is like IDs, but panics if an error occurs. |
| 272 |
func (_q *DsseQuery) IDsX(ctx context.Context) []uuid.UUID { |
| 273 |
ids, err := _q.IDs(ctx) |
| 274 |
if err != nil { |
| 275 |
panic(err) |
| 276 |
} |
| 277 |
return ids |
| 278 |
} |
| 279 |
|
| 280 |
// Count returns the count of the given query. |
| 281 |
func (_q *DsseQuery) Count(ctx context.Context) (int, error) { |
| 282 |
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) |
| 283 |
if err := _q.prepareQuery(ctx); err != nil { |
| 284 |
return 0, err |
| 285 |
} |
| 286 |
return withInterceptors[int](ctx, _q, querierCount[*DsseQuery](), _q.inters) |
| 287 |
} |
| 288 |
|
| 289 |
// CountX is like Count, but panics if an error occurs. |
| 290 |
func (_q *DsseQuery) CountX(ctx context.Context) int { |
| 291 |
count, err := _q.Count(ctx) |
| 292 |
if err != nil { |
| 293 |
panic(err) |
| 294 |
} |
| 295 |
return count |
| 296 |
} |
| 297 |
|
| 298 |
// Exist returns true if the query has elements in the graph. |
| 299 |
func (_q *DsseQuery) Exist(ctx context.Context) (bool, error) { |
| 300 |
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) |
| 301 |
switch _, err := _q.FirstID(ctx); { |
| 302 |
case IsNotFound(err): |
| 303 |
return false, nil |
| 304 |
case err != nil: |
| 305 |
return false, fmt.Errorf("ent: check existence: %w", err) |
| 306 |
default: |
| 307 |
return true, nil |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
// ExistX is like Exist, but panics if an error occurs. |
| 312 |
func (_q *DsseQuery) ExistX(ctx context.Context) bool { |
| 313 |
exist, err := _q.Exist(ctx) |
| 314 |
if err != nil { |
| 315 |
panic(err) |
| 316 |
} |
| 317 |
return exist |
| 318 |
} |
| 319 |
|
| 320 |
// Clone returns a duplicate of the DsseQuery builder, including all associated steps. It can be |
| 321 |
// used to prepare common query builders and use them differently after the clone is made. |
| 322 |
func (_q *DsseQuery) Clone() *DsseQuery { |
| 323 |
if _q == nil { |
| 324 |
return nil |
| 325 |
} |
| 326 |
return &DsseQuery{ |
| 327 |
config: _q.config, |
| 328 |
ctx: _q.ctx.Clone(), |
| 329 |
order: append([]dsse.OrderOption{}, _q.order...), |
| 330 |
inters: append([]Interceptor{}, _q.inters...), |
| 331 |
predicates: append([]predicate.Dsse{}, _q.predicates...), |
| 332 |
withStatement: _q.withStatement.Clone(), |
| 333 |
withSignatures: _q.withSignatures.Clone(), |
| 334 |
withPayloadDigests: _q.withPayloadDigests.Clone(), |
| 335 |
// clone intermediate query. |
| 336 |
sql: _q.sql.Clone(), |
| 337 |
path: _q.path, |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
// WithStatement tells the query-builder to eager-load the nodes that are connected to |
| 342 |
// the "statement" edge. The optional arguments are used to configure the query builder of the edge. |
| 343 |
func (_q *DsseQuery) WithStatement(opts ...func(*StatementQuery)) *DsseQuery { |
| 344 |
query := (&StatementClient{config: _q.config}).Query() |
| 345 |
for _, opt := range opts { |
| 346 |
opt(query) |
| 347 |
} |
| 348 |
_q.withStatement = query |
| 349 |
return _q |
| 350 |
} |
| 351 |
|
| 352 |
// WithSignatures tells the query-builder to eager-load the nodes that are connected to |
| 353 |
// the "signatures" edge. The optional arguments are used to configure the query builder of the edge. |
| 354 |
func (_q *DsseQuery) WithSignatures(opts ...func(*SignatureQuery)) *DsseQuery { |
| 355 |
query := (&SignatureClient{config: _q.config}).Query() |
| 356 |
for _, opt := range opts { |
| 357 |
opt(query) |
| 358 |
} |
| 359 |
_q.withSignatures = query |
| 360 |
return _q |
| 361 |
} |
| 362 |
|
| 363 |
// WithPayloadDigests tells the query-builder to eager-load the nodes that are connected to |
| 364 |
// the "payload_digests" edge. The optional arguments are used to configure the query builder of the edge. |
| 365 |
func (_q *DsseQuery) WithPayloadDigests(opts ...func(*PayloadDigestQuery)) *DsseQuery { |
| 366 |
query := (&PayloadDigestClient{config: _q.config}).Query() |
| 367 |
for _, opt := range opts { |
| 368 |
opt(query) |
| 369 |
} |
| 370 |
_q.withPayloadDigests = query |
| 371 |
return _q |
| 372 |
} |
| 373 |
|
| 374 |
// GroupBy is used to group vertices by one or more fields/columns. |
| 375 |
// It is often used with aggregate functions, like: count, max, mean, min, sum. |
| 376 |
// |
| 377 |
// Example: |
| 378 |
// |
| 379 |
// var v []struct { |
| 380 |
// CreatedAt time.Time `json:"created_at,omitempty"` |
| 381 |
// Count int `json:"count,omitempty"` |
| 382 |
// } |
| 383 |
// |
| 384 |
// client.Dsse.Query(). |
| 385 |
// GroupBy(dsse.FieldCreatedAt). |
| 386 |
// Aggregate(ent.Count()). |
| 387 |
// Scan(ctx, &v) |
| 388 |
func (_q *DsseQuery) GroupBy(field string, fields ...string) *DsseGroupBy { |
| 389 |
_q.ctx.Fields = append([]string{field}, fields...) |
| 390 |
grbuild := &DsseGroupBy{build: _q} |
| 391 |
grbuild.flds = &_q.ctx.Fields |
| 392 |
grbuild.label = dsse.Label |
| 393 |
grbuild.scan = grbuild.Scan |
| 394 |
return grbuild |
| 395 |
} |
| 396 |
|
| 397 |
// Select allows the selection one or more fields/columns for the given query, |
| 398 |
// instead of selecting all fields in the entity. |
| 399 |
// |
| 400 |
// Example: |
| 401 |
// |
| 402 |
// var v []struct { |
| 403 |
// CreatedAt time.Time `json:"created_at,omitempty"` |
| 404 |
// } |
| 405 |
// |
| 406 |
// client.Dsse.Query(). |
| 407 |
// Select(dsse.FieldCreatedAt). |
| 408 |
// Scan(ctx, &v) |
| 409 |
func (_q *DsseQuery) Select(fields ...string) *DsseSelect { |
| 410 |
_q.ctx.Fields = append(_q.ctx.Fields, fields...) |
| 411 |
sbuild := &DsseSelect{DsseQuery: _q} |
| 412 |
sbuild.label = dsse.Label |
| 413 |
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan |
| 414 |
return sbuild |
| 415 |
} |
| 416 |
|
| 417 |
// Aggregate returns a DsseSelect configured with the given aggregations. |
| 418 |
func (_q *DsseQuery) Aggregate(fns ...AggregateFunc) *DsseSelect { |
| 419 |
return _q.Select().Aggregate(fns...) |
| 420 |
} |
| 421 |
|
| 422 |
func (_q *DsseQuery) prepareQuery(ctx context.Context) error { |
| 423 |
for _, inter := range _q.inters { |
| 424 |
if inter == nil { |
| 425 |
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") |
| 426 |
} |
| 427 |
if trv, ok := inter.(Traverser); ok { |
| 428 |
if err := trv.Traverse(ctx, _q); err != nil { |
| 429 |
return err |
| 430 |
} |
| 431 |
} |
| 432 |
} |
| 433 |
for _, f := range _q.ctx.Fields { |
| 434 |
if !dsse.ValidColumn(f) { |
| 435 |
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} |
| 436 |
} |
| 437 |
} |
| 438 |
if _q.path != nil { |
| 439 |
prev, err := _q.path(ctx) |
| 440 |
if err != nil { |
| 441 |
return err |
| 442 |
} |
| 443 |
_q.sql = prev |
| 444 |
} |
| 445 |
return nil |
| 446 |
} |
| 447 |
|
| 448 |
func (_q *DsseQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Dsse, error) { |
| 449 |
var ( |
| 450 |
nodes = []*Dsse{} |
| 451 |
withFKs = _q.withFKs |
| 452 |
_spec = _q.querySpec() |
| 453 |
loadedTypes = [3]bool{ |
| 454 |
_q.withStatement != nil, |
| 455 |
_q.withSignatures != nil, |
| 456 |
_q.withPayloadDigests != nil, |
| 457 |
} |
| 458 |
) |
| 459 |
if _q.withStatement != nil { |
| 460 |
withFKs = true |
| 461 |
} |
| 462 |
if withFKs { |
| 463 |
_spec.Node.Columns = append(_spec.Node.Columns, dsse.ForeignKeys...) |
| 464 |
} |
| 465 |
_spec.ScanValues = func(columns []string) ([]any, error) { |
| 466 |
return (*Dsse).scanValues(nil, columns) |
| 467 |
} |
| 468 |
_spec.Assign = func(columns []string, values []any) error { |
| 469 |
node := &Dsse{config: _q.config} |
| 470 |
nodes = append(nodes, node) |
| 471 |
node.Edges.loadedTypes = loadedTypes |
| 472 |
return node.assignValues(columns, values) |
| 473 |
} |
| 474 |
if len(_q.modifiers) > 0 { |
| 475 |
_spec.Modifiers = _q.modifiers |
| 476 |
} |
| 477 |
for i := range hooks { |
| 478 |
hooks[i](ctx, _spec) |
| 479 |
} |
| 480 |
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { |
| 481 |
return nil, err |
| 482 |
} |
| 483 |
if len(nodes) == 0 { |
| 484 |
return nodes, nil |
| 485 |
} |
| 486 |
if query := _q.withStatement; query != nil { |
| 487 |
if err := _q.loadStatement(ctx, query, nodes, nil, |
| 488 |
func(n *Dsse, e *Statement) { n.Edges.Statement = e }); err != nil { |
| 489 |
return nil, err |
| 490 |
} |
| 491 |
} |
| 492 |
if query := _q.withSignatures; query != nil { |
| 493 |
if err := _q.loadSignatures(ctx, query, nodes, |
| 494 |
func(n *Dsse) { n.Edges.Signatures = []*Signature{} }, |
| 495 |
func(n *Dsse, e *Signature) { n.Edges.Signatures = append(n.Edges.Signatures, e) }); err != nil { |
| 496 |
return nil, err |
| 497 |
} |
| 498 |
} |
| 499 |
if query := _q.withPayloadDigests; query != nil { |
| 500 |
if err := _q.loadPayloadDigests(ctx, query, nodes, |
| 501 |
func(n *Dsse) { n.Edges.PayloadDigests = []*PayloadDigest{} }, |
| 502 |
func(n *Dsse, e *PayloadDigest) { n.Edges.PayloadDigests = append(n.Edges.PayloadDigests, e) }); err != nil { |
| 503 |
return nil, err |
| 504 |
} |
| 505 |
} |
| 506 |
for name, query := range _q.withNamedSignatures { |
| 507 |
if err := _q.loadSignatures(ctx, query, nodes, |
| 508 |
func(n *Dsse) { n.appendNamedSignatures(name) }, |
| 509 |
func(n *Dsse, e *Signature) { n.appendNamedSignatures(name, e) }); err != nil { |
| 510 |
return nil, err |
| 511 |
} |
| 512 |
} |
| 513 |
for name, query := range _q.withNamedPayloadDigests { |
| 514 |
if err := _q.loadPayloadDigests(ctx, query, nodes, |
| 515 |
func(n *Dsse) { n.appendNamedPayloadDigests(name) }, |
| 516 |
func(n *Dsse, e *PayloadDigest) { n.appendNamedPayloadDigests(name, e) }); err != nil { |
| 517 |
return nil, err |
| 518 |
} |
| 519 |
} |
| 520 |
for i := range _q.loadTotal { |
| 521 |
if err := _q.loadTotal[i](ctx, nodes); err != nil { |
| 522 |
return nil, err |
| 523 |
} |
| 524 |
} |
| 525 |
return nodes, nil |
| 526 |
} |
| 527 |
|
| 528 |
func (_q *DsseQuery) loadStatement(ctx context.Context, query *StatementQuery, nodes []*Dsse, init func(*Dsse), assign func(*Dsse, *Statement)) error { |
| 529 |
ids := make([]uuid.UUID, 0, len(nodes)) |
| 530 |
nodeids := make(map[uuid.UUID][]*Dsse) |
| 531 |
for i := range nodes { |
| 532 |
if nodes[i].dsse_statement == nil { |
| 533 |
continue |
| 534 |
} |
| 535 |
fk := *nodes[i].dsse_statement |
| 536 |
if _, ok := nodeids[fk]; !ok { |
| 537 |
ids = append(ids, fk) |
| 538 |
} |
| 539 |
nodeids[fk] = append(nodeids[fk], nodes[i]) |
| 540 |
} |
| 541 |
if len(ids) == 0 { |
| 542 |
return nil |
| 543 |
} |
| 544 |
query.Where(statement.IDIn(ids...)) |
| 545 |
neighbors, err := query.All(ctx) |
| 546 |
if err != nil { |
| 547 |
return err |
| 548 |
} |
| 549 |
for _, n := range neighbors { |
| 550 |
nodes, ok := nodeids[n.ID] |
| 551 |
if !ok { |
| 552 |
return fmt.Errorf(`unexpected foreign-key "dsse_statement" returned %v`, n.ID) |
| 553 |
} |
| 554 |
for i := range nodes { |
| 555 |
assign(nodes[i], n) |
| 556 |
} |
| 557 |
} |
| 558 |
return nil |
| 559 |
} |
| 560 |
func (_q *DsseQuery) loadSignatures(ctx context.Context, query *SignatureQuery, nodes []*Dsse, init func(*Dsse), assign func(*Dsse, *Signature)) error { |
| 561 |
fks := make([]driver.Value, 0, len(nodes)) |
| 562 |
nodeids := make(map[uuid.UUID]*Dsse) |
| 563 |
for i := range nodes { |
| 564 |
fks = append(fks, nodes[i].ID) |
| 565 |
nodeids[nodes[i].ID] = nodes[i] |
| 566 |
if init != nil { |
| 567 |
init(nodes[i]) |
| 568 |
} |
| 569 |
} |
| 570 |
query.withFKs = true |
| 571 |
query.Where(predicate.Signature(func(s *sql.Selector) { |
| 572 |
s.Where(sql.InValues(s.C(dsse.SignaturesColumn), fks...)) |
| 573 |
})) |
| 574 |
neighbors, err := query.All(ctx) |
| 575 |
if err != nil { |
| 576 |
return err |
| 577 |
} |
| 578 |
for _, n := range neighbors { |
| 579 |
fk := n.dsse_signatures |
| 580 |
if fk == nil { |
| 581 |
return fmt.Errorf(`foreign-key "dsse_signatures" is nil for node %v`, n.ID) |
| 582 |
} |
| 583 |
node, ok := nodeids[*fk] |
| 584 |
if !ok { |
| 585 |
return fmt.Errorf(`unexpected referenced foreign-key "dsse_signatures" returned %v for node %v`, *fk, n.ID) |
| 586 |
} |
| 587 |
assign(node, n) |
| 588 |
} |
| 589 |
return nil |
| 590 |
} |
| 591 |
func (_q *DsseQuery) loadPayloadDigests(ctx context.Context, query *PayloadDigestQuery, nodes []*Dsse, init func(*Dsse), assign func(*Dsse, *PayloadDigest)) error { |
| 592 |
fks := make([]driver.Value, 0, len(nodes)) |
| 593 |
nodeids := make(map[uuid.UUID]*Dsse) |
| 594 |
for i := range nodes { |
| 595 |
fks = append(fks, nodes[i].ID) |
| 596 |
nodeids[nodes[i].ID] = nodes[i] |
| 597 |
if init != nil { |
| 598 |
init(nodes[i]) |
| 599 |
} |
| 600 |
} |
| 601 |
query.withFKs = true |
| 602 |
query.Where(predicate.PayloadDigest(func(s *sql.Selector) { |
| 603 |
s.Where(sql.InValues(s.C(dsse.PayloadDigestsColumn), fks...)) |
| 604 |
})) |
| 605 |
neighbors, err := query.All(ctx) |
| 606 |
if err != nil { |
| 607 |
return err |
| 608 |
} |
| 609 |
for _, n := range neighbors { |
| 610 |
fk := n.dsse_payload_digests |
| 611 |
if fk == nil { |
| 612 |
return fmt.Errorf(`foreign-key "dsse_payload_digests" is nil for node %v`, n.ID) |
| 613 |
} |
| 614 |
node, ok := nodeids[*fk] |
| 615 |
if !ok { |
| 616 |
return fmt.Errorf(`unexpected referenced foreign-key "dsse_payload_digests" returned %v for node %v`, *fk, n.ID) |
| 617 |
} |
| 618 |
assign(node, n) |
| 619 |
} |
| 620 |
return nil |
| 621 |
} |
| 622 |
|
| 623 |
func (_q *DsseQuery) sqlCount(ctx context.Context) (int, error) { |
| 624 |
_spec := _q.querySpec() |
| 625 |
if len(_q.modifiers) > 0 { |
| 626 |
_spec.Modifiers = _q.modifiers |
| 627 |
} |
| 628 |
_spec.Node.Columns = _q.ctx.Fields |
| 629 |
if len(_q.ctx.Fields) > 0 { |
| 630 |
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique |
| 631 |
} |
| 632 |
return sqlgraph.CountNodes(ctx, _q.driver, _spec) |
| 633 |
} |
| 634 |
|
| 635 |
func (_q *DsseQuery) querySpec() *sqlgraph.QuerySpec { |
| 636 |
_spec := sqlgraph.NewQuerySpec(dsse.Table, dsse.Columns, sqlgraph.NewFieldSpec(dsse.FieldID, field.TypeUUID)) |
| 637 |
_spec.From = _q.sql |
| 638 |
if unique := _q.ctx.Unique; unique != nil { |
| 639 |
_spec.Unique = *unique |
| 640 |
} else if _q.path != nil { |
| 641 |
_spec.Unique = true |
| 642 |
} |
| 643 |
if fields := _q.ctx.Fields; len(fields) > 0 { |
| 644 |
_spec.Node.Columns = make([]string, 0, len(fields)) |
| 645 |
_spec.Node.Columns = append(_spec.Node.Columns, dsse.FieldID) |
| 646 |
for i := range fields { |
| 647 |
if fields[i] != dsse.FieldID { |
| 648 |
_spec.Node.Columns = append(_spec.Node.Columns, fields[i]) |
| 649 |
} |
| 650 |
} |
| 651 |
} |
| 652 |
if ps := _q.predicates; len(ps) > 0 { |
| 653 |
_spec.Predicate = func(selector *sql.Selector) { |
| 654 |
for i := range ps { |
| 655 |
ps[i](selector) |
| 656 |
} |
| 657 |
} |
| 658 |
} |
| 659 |
if limit := _q.ctx.Limit; limit != nil { |
| 660 |
_spec.Limit = *limit |
| 661 |
} |
| 662 |
if offset := _q.ctx.Offset; offset != nil { |
| 663 |
_spec.Offset = *offset |
| 664 |
} |
| 665 |
if ps := _q.order; len(ps) > 0 { |
| 666 |
_spec.Order = func(selector *sql.Selector) { |
| 667 |
for i := range ps { |
| 668 |
ps[i](selector) |
| 669 |
} |
| 670 |
} |
| 671 |
} |
| 672 |
return _spec |
| 673 |
} |
| 674 |
|
| 675 |
func (_q *DsseQuery) sqlQuery(ctx context.Context) *sql.Selector { |
| 676 |
builder := sql.Dialect(_q.driver.Dialect()) |
| 677 |
t1 := builder.Table(dsse.Table) |
| 678 |
columns := _q.ctx.Fields |
| 679 |
if len(columns) == 0 { |
| 680 |
columns = dsse.Columns |
| 681 |
} |
| 682 |
selector := builder.Select(t1.Columns(columns...)...).From(t1) |
| 683 |
if _q.sql != nil { |
| 684 |
selector = _q.sql |
| 685 |
selector.Select(selector.Columns(columns...)...) |
| 686 |
} |
| 687 |
if _q.ctx.Unique != nil && *_q.ctx.Unique { |
| 688 |
selector.Distinct() |
| 689 |
} |
| 690 |
for _, p := range _q.predicates { |
| 691 |
p(selector) |
| 692 |
} |
| 693 |
for _, p := range _q.order { |
| 694 |
p(selector) |
| 695 |
} |
| 696 |
if offset := _q.ctx.Offset; offset != nil { |
| 697 |
// limit is mandatory for offset clause. We start |
| 698 |
// with default value, and override it below if needed. |
| 699 |
selector.Offset(*offset).Limit(math.MaxInt32) |
| 700 |
} |
| 701 |
if limit := _q.ctx.Limit; limit != nil { |
| 702 |
selector.Limit(*limit) |
| 703 |
} |
| 704 |
return selector |
| 705 |
} |
| 706 |
|
| 707 |
// WithNamedSignatures tells the query-builder to eager-load the nodes that are connected to the "signatures" |
| 708 |
// edge with the given name. The optional arguments are used to configure the query builder of the edge. |
| 709 |
func (_q *DsseQuery) WithNamedSignatures(name string, opts ...func(*SignatureQuery)) *DsseQuery { |
| 710 |
query := (&SignatureClient{config: _q.config}).Query() |
| 711 |
for _, opt := range opts { |
| 712 |
opt(query) |
| 713 |
} |
| 714 |
if _q.withNamedSignatures == nil { |
| 715 |
_q.withNamedSignatures = make(map[string]*SignatureQuery) |
| 716 |
} |
| 717 |
_q.withNamedSignatures[name] = query |
| 718 |
return _q |
| 719 |
} |
| 720 |
|
| 721 |
// WithNamedPayloadDigests tells the query-builder to eager-load the nodes that are connected to the "payload_digests" |
| 722 |
// edge with the given name. The optional arguments are used to configure the query builder of the edge. |
| 723 |
func (_q *DsseQuery) WithNamedPayloadDigests(name string, opts ...func(*PayloadDigestQuery)) *DsseQuery { |
| 724 |
query := (&PayloadDigestClient{config: _q.config}).Query() |
| 725 |
for _, opt := range opts { |
| 726 |
opt(query) |
| 727 |
} |
| 728 |
if _q.withNamedPayloadDigests == nil { |
| 729 |
_q.withNamedPayloadDigests = make(map[string]*PayloadDigestQuery) |
| 730 |
} |
| 731 |
_q.withNamedPayloadDigests[name] = query |
| 732 |
return _q |
| 733 |
} |
| 734 |
|
| 735 |
// DsseGroupBy is the group-by builder for Dsse entities. |
| 736 |
type DsseGroupBy struct { |
| 737 |
selector |
| 738 |
build *DsseQuery |
| 739 |
} |
| 740 |
|
| 741 |
// Aggregate adds the given aggregation functions to the group-by query. |
| 742 |
func (_g *DsseGroupBy) Aggregate(fns ...AggregateFunc) *DsseGroupBy { |
| 743 |
_g.fns = append(_g.fns, fns...) |
| 744 |
return _g |
| 745 |
} |
| 746 |
|
| 747 |
// Scan applies the selector query and scans the result into the given value. |
| 748 |
func (_g *DsseGroupBy) Scan(ctx context.Context, v any) error { |
| 749 |
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) |
| 750 |
if err := _g.build.prepareQuery(ctx); err != nil { |
| 751 |
return err |
| 752 |
} |
| 753 |
return scanWithInterceptors[*DsseQuery, *DsseGroupBy](ctx, _g.build, _g, _g.build.inters, v) |
| 754 |
} |
| 755 |
|
| 756 |
func (_g *DsseGroupBy) sqlScan(ctx context.Context, root *DsseQuery, v any) error { |
| 757 |
selector := root.sqlQuery(ctx).Select() |
| 758 |
aggregation := make([]string, 0, len(_g.fns)) |
| 759 |
for _, fn := range _g.fns { |
| 760 |
aggregation = append(aggregation, fn(selector)) |
| 761 |
} |
| 762 |
if len(selector.SelectedColumns()) == 0 { |
| 763 |
columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) |
| 764 |
for _, f := range *_g.flds { |
| 765 |
columns = append(columns, selector.C(f)) |
| 766 |
} |
| 767 |
columns = append(columns, aggregation...) |
| 768 |
selector.Select(columns...) |
| 769 |
} |
| 770 |
selector.GroupBy(selector.Columns(*_g.flds...)...) |
| 771 |
if err := selector.Err(); err != nil { |
| 772 |
return err |
| 773 |
} |
| 774 |
rows := &sql.Rows{} |
| 775 |
query, args := selector.Query() |
| 776 |
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { |
| 777 |
return err |
| 778 |
} |
| 779 |
defer rows.Close() |
| 780 |
return sql.ScanSlice(rows, v) |
| 781 |
} |
| 782 |
|
| 783 |
// DsseSelect is the builder for selecting fields of Dsse entities. |
| 784 |
type DsseSelect struct { |
| 785 |
*DsseQuery |
| 786 |
selector |
| 787 |
} |
| 788 |
|
| 789 |
// Aggregate adds the given aggregation functions to the selector query. |
| 790 |
func (_s *DsseSelect) Aggregate(fns ...AggregateFunc) *DsseSelect { |
| 791 |
_s.fns = append(_s.fns, fns...) |
| 792 |
return _s |
| 793 |
} |
| 794 |
|
| 795 |
// Scan applies the selector query and scans the result into the given value. |
| 796 |
func (_s *DsseSelect) Scan(ctx context.Context, v any) error { |
| 797 |
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) |
| 798 |
if err := _s.prepareQuery(ctx); err != nil { |
| 799 |
return err |
| 800 |
} |
| 801 |
return scanWithInterceptors[*DsseQuery, *DsseSelect](ctx, _s.DsseQuery, _s, _s.inters, v) |
| 802 |
} |
| 803 |
|
| 804 |
func (_s *DsseSelect) sqlScan(ctx context.Context, root *DsseQuery, v any) error { |
| 805 |
selector := root.sqlQuery(ctx) |
| 806 |
aggregation := make([]string, 0, len(_s.fns)) |
| 807 |
for _, fn := range _s.fns { |
| 808 |
aggregation = append(aggregation, fn(selector)) |
| 809 |
} |
| 810 |
switch n := len(*_s.selector.flds); { |
| 811 |
case n == 0 && len(aggregation) > 0: |
| 812 |
selector.Select(aggregation...) |
| 813 |
case n != 0 && len(aggregation) > 0: |
| 814 |
selector.AppendSelect(aggregation...) |
| 815 |
} |
| 816 |
rows := &sql.Rows{} |
| 817 |
query, args := selector.Query() |
| 818 |
if err := _s.driver.Query(ctx, query, args, rows); err != nil { |
| 819 |
return err |
| 820 |
} |
| 821 |
defer rows.Close() |
| 822 |
return sql.ScanSlice(rows, v) |
| 823 |
} |