MCPcopy
hub / github.com/crowdsecurity/crowdsec / sqlQuery

Method sqlQuery

pkg/database/ent/meta_query.go:486–516  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

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

Callers 3

QueryOwnerMethod · 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