MCPcopy Create free account
hub / github.com/crowdsecurity/crowdsec / sqlAll

Method sqlAll

pkg/database/ent/alert_query.go:479–543  ·  view source on GitHub ↗
(ctx context.Context, hooks ...queryHook)

Source from the content-addressed store, hash-verified

477}
478
479func (_q *AlertQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Alert, error) {
480 var (
481 nodes = []*Alert{}
482 withFKs = _q.withFKs
483 _spec = _q.querySpec()
484 loadedTypes = [4]bool{
485 _q.withOwner != nil,
486 _q.withDecisions != nil,
487 _q.withEvents != nil,
488 _q.withMetas != nil,
489 }
490 )
491 if _q.withOwner != nil {
492 withFKs = true
493 }
494 if withFKs {
495 _spec.Node.Columns = append(_spec.Node.Columns, alert.ForeignKeys...)
496 }
497 _spec.ScanValues = func(columns []string) ([]any, error) {
498 return (*Alert).scanValues(nil, columns)
499 }
500 _spec.Assign = func(columns []string, values []any) error {
501 node := &Alert{config: _q.config}
502 nodes = append(nodes, node)
503 node.Edges.loadedTypes = loadedTypes
504 return node.assignValues(columns, values)
505 }
506 for i := range hooks {
507 hooks[i](ctx, _spec)
508 }
509 if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
510 return nil, err
511 }
512 if len(nodes) == 0 {
513 return nodes, nil
514 }
515 if query := _q.withOwner; query != nil {
516 if err := _q.loadOwner(ctx, query, nodes, nil,
517 func(n *Alert, e *Machine) { n.Edges.Owner = e }); err != nil {
518 return nil, err
519 }
520 }
521 if query := _q.withDecisions; query != nil {
522 if err := _q.loadDecisions(ctx, query, nodes,
523 func(n *Alert) { n.Edges.Decisions = []*Decision{} },
524 func(n *Alert, e *Decision) { n.Edges.Decisions = append(n.Edges.Decisions, e) }); err != nil {
525 return nil, err
526 }
527 }
528 if query := _q.withEvents; query != nil {
529 if err := _q.loadEvents(ctx, query, nodes,
530 func(n *Alert) { n.Edges.Events = []*Event{} },
531 func(n *Alert, e *Event) { n.Edges.Events = append(n.Edges.Events, e) }); err != nil {
532 return nil, err
533 }
534 }
535 if query := _q.withMetas; query != nil {
536 if err := _q.loadMetas(ctx, query, nodes,

Callers

nothing calls this directly

Calls 7

querySpecMethod · 0.95
assignValuesMethod · 0.95
loadOwnerMethod · 0.95
loadDecisionsMethod · 0.95
loadEventsMethod · 0.95
loadMetasMethod · 0.95
scanValuesMethod · 0.45

Tested by

no test coverage detected