MCPcopy Index your code
hub / github.com/crowdsecurity/crowdsec / sqlQuery

Method sqlQuery

pkg/database/ent/machine_query.go:487–517  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

485}
486
487func (_q *MachineQuery) sqlQuery(ctx context.Context) *sql.Selector {
488 builder := sql.Dialect(_q.driver.Dialect())
489 t1 := builder.Table(machine.Table)
490 columns := _q.ctx.Fields
491 if len(columns) == 0 {
492 columns = machine.Columns
493 }
494 selector := builder.Select(t1.Columns(columns...)...).From(t1)
495 if _q.sql != nil {
496 selector = _q.sql
497 selector.Select(selector.Columns(columns...)...)
498 }
499 if _q.ctx.Unique != nil && *_q.ctx.Unique {
500 selector.Distinct()
501 }
502 for _, p := range _q.predicates {
503 p(selector)
504 }
505 for _, p := range _q.order {
506 p(selector)
507 }
508 if offset := _q.ctx.Offset; offset != nil {
509 // limit is mandatory for offset clause. We start
510 // with default value, and override it below if needed.
511 selector.Offset(*offset).Limit(math.MaxInt32)
512 }
513 if limit := _q.ctx.Limit; limit != nil {
514 selector.Limit(*limit)
515 }
516 return selector
517}
518
519// MachineGroupBy is the group-by builder for Machine entities.
520type MachineGroupBy struct {

Callers 3

QueryAlertsMethod · 0.95
sqlScanMethod · 0.45
sqlScanMethod · 0.45

Calls 5

DialectMethod · 0.80
TableMethod · 0.65
SelectMethod · 0.45
LimitMethod · 0.45
OffsetMethod · 0.45

Tested by

no test coverage detected