-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathteam.go
40 lines (32 loc) · 780 Bytes
/
team.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"database/sql"
"fmt"
"log"
)
type teamRow struct {
Team string `json:"team"`
FirstPre int `json:"firstPre"`
LatestPre int `json:"latestPre"`
Count int `json:"count"`
}
const maxListedTeams = 1000
func listTeams(tx *sql.Tx) ([]teamRow, error) {
sqlQuery := fmt.Sprintf("SELECT team, MIN(pre_at), MAX(pre_at), COUNT(*) AS count FROM %s GROUP BY team ORDER BY count DESC LIMIT %d", sphinxTable, maxListedTeams)
rows, err := tx.Query(sqlQuery)
if err != nil {
return nil, err
}
defer rows.Close()
res := make([]teamRow, 0)
for rows.Next() {
var r teamRow
err := rows.Scan(&r.Team, &r.FirstPre, &r.LatestPre, &r.Count)
if err != nil {
log.Print(err)
continue
}
res = append(res, r)
}
return res, nil
}