···170171// this is a mega query, but the most useful one:
172// get N pipelines, for each one get the latest status of its N workflows
000173func GetPipelineStatuses(e Execer, limit int, filters ...orm.Filter) ([]models.Pipeline, error) {
174 var conditions []string
175 var args []any
176 for _, filter := range filters {
177- filter.Key = "p." + filter.Key // the table is aliased in the query to `p`
178 conditions = append(conditions, filter.Condition())
179 args = append(args, filter.Arg()...)
180 }
···366367 return all, nil
368}
000000000000000000000000000000000000000000000
···170171// this is a mega query, but the most useful one:
172// get N pipelines, for each one get the latest status of its N workflows
173+//
174+// the pipelines table is aliased to `p`
175+// the triggers table is aliased to `t`
176func GetPipelineStatuses(e Execer, limit int, filters ...orm.Filter) ([]models.Pipeline, error) {
177 var conditions []string
178 var args []any
179 for _, filter := range filters {
0180 conditions = append(conditions, filter.Condition())
181 args = append(args, filter.Arg()...)
182 }
···368369 return all, nil
370}
371+372+// the pipelines table is aliased to `p`
373+// the triggers table is aliased to `t`
374+func GetTotalPipelineStatuses(e Execer, filters ...orm.Filter) (int64, error) {
375+ var conditions []string
376+ var args []any
377+ for _, filter := range filters {
378+ conditions = append(conditions, filter.Condition())
379+ args = append(args, filter.Arg()...)
380+ }
381+382+ whereClause := ""
383+ if conditions != nil {
384+ whereClause = " where " + strings.Join(conditions, " and ")
385+ }
386+387+ query := fmt.Sprintf(`
388+ select
389+ count(1)
390+ from
391+ pipelines p
392+ join
393+ triggers t ON p.trigger_id = t.id
394+ %s
395+ `, whereClause)
396+397+ rows, err := e.Query(query, args...)
398+ if err != nil {
399+ return 0, err
400+ }
401+ defer rows.Close()
402+403+ for rows.Next() {
404+ var count int64
405+ err := rows.Scan(&count)
406+ if err != nil {
407+ return 0, err
408+ }
409+410+ return count, nil
411+ }
412+413+ // unreachable
414+ return 0, nil
415+}