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

Method sqlQuery

pkg/database/ent/alert_query.go:717–747  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

715}
716
717func (_q *AlertQuery) sqlQuery(ctx context.Context) *sql.Selector {
718 builder := sql.Dialect(_q.driver.Dialect())
719 t1 := builder.Table(alert.Table)
720 columns := _q.ctx.Fields
721 if len(columns) == 0 {
722 columns = alert.Columns
723 }
724 selector := builder.Select(t1.Columns(columns...)...).From(t1)
725 if _q.sql != nil {
726 selector = _q.sql
727 selector.Select(selector.Columns(columns...)...)
728 }
729 if _q.ctx.Unique != nil && *_q.ctx.Unique {
730 selector.Distinct()
731 }
732 for _, p := range _q.predicates {
733 p(selector)
734 }
735 for _, p := range _q.order {
736 p(selector)
737 }
738 if offset := _q.ctx.Offset; offset != nil {
739 // limit is mandatory for offset clause. We start
740 // with default value, and override it below if needed.
741 selector.Offset(*offset).Limit(math.MaxInt32)
742 }
743 if limit := _q.ctx.Limit; limit != nil {
744 selector.Limit(*limit)
745 }
746 return selector
747}
748
749// AlertGroupBy is the group-by builder for Alert entities.
750type AlertGroupBy struct {

Callers 6

QueryOwnerMethod · 0.95
QueryDecisionsMethod · 0.95
QueryEventsMethod · 0.95
QueryMetasMethod · 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