-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan.go
71 lines (63 loc) · 1.59 KB
/
scan.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Drone Non-Commercial License
// that can be found in the LICENSE file.
// +build !oss
package cron
import (
"database/sql"
"github.com/ozonep/drone/core"
"github.com/ozonep/drone/store/shared/db"
)
// helper function converts the User structure to a set
// of named query parameters.
func toParams(cron *core.Cron) map[string]interface{} {
return map[string]interface{}{
"cron_id": cron.ID,
"cron_repo_id": cron.RepoID,
"cron_name": cron.Name,
"cron_expr": cron.Expr,
"cron_next": cron.Next,
"cron_prev": cron.Prev,
"cron_event": cron.Event,
"cron_branch": cron.Branch,
"cron_target": cron.Target,
"cron_disabled": cron.Disabled,
"cron_created": cron.Created,
"cron_updated": cron.Updated,
"cron_version": cron.Version,
}
}
// helper function scans the sql.Row and copies the column
// values to the destination object.
func scanRow(scanner db.Scanner, dst *core.Cron) error {
return scanner.Scan(
&dst.ID,
&dst.RepoID,
&dst.Name,
&dst.Expr,
&dst.Next,
&dst.Prev,
&dst.Event,
&dst.Branch,
&dst.Target,
&dst.Disabled,
&dst.Created,
&dst.Updated,
&dst.Version,
)
}
// helper function scans the sql.Row and copies the column
// values to the destination object.
func scanRows(rows *sql.Rows) ([]*core.Cron, error) {
defer rows.Close()
crons := []*core.Cron{}
for rows.Next() {
cron := new(core.Cron)
err := scanRow(rows, cron)
if err != nil {
return nil, err
}
crons = append(crons, cron)
}
return crons, nil
}