forked from vmware-archive/atc
/
sqldb_pipelines.go
54 lines (43 loc) · 1.2 KB
/
sqldb_pipelines.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package db
//go:generate counterfeiter . PipelinesDB
type PipelinesDB interface {
GetAllPublicPipelines() ([]SavedPipeline, error)
}
const pipelineColumns = "p.id, p.name, p.config, p.version, p.paused, p.team_id, p.public, t.name as team_name"
const unqualifiedPipelineColumns = "id, name, config, version, paused, team_id, public"
func (db *SQLDB) GetAllPublicPipelines() ([]SavedPipeline, error) {
rows, err := db.conn.Query(`
SELECT ` + pipelineColumns + `
FROM pipelines p
INNER JOIN teams t ON t.id = p.team_id
WHERE p.public = true
ORDER BY team_name, ordering
`)
if err != nil {
return nil, err
}
defer rows.Close()
return scanPipelines(rows)
}
func (db *SQLDB) GetAllPipelines() ([]SavedPipeline, error) {
rows, err := db.conn.Query(`
SELECT ` + pipelineColumns + `
FROM pipelines p
INNER JOIN teams t ON t.id = p.team_id
ORDER BY ordering
`)
if err != nil {
return nil, err
}
defer rows.Close()
return scanPipelines(rows)
}
func (db *SQLDB) GetPipelineByID(pipelineID int) (SavedPipeline, error) {
row := db.conn.QueryRow(`
SELECT `+pipelineColumns+`
FROM pipelines p
INNER JOIN teams t ON t.id = p.team_id
WHERE p.id = $1
`, pipelineID)
return scanPipeline(row)
}