harness-drone/store/step/scan.go
2019-02-19 15:56:41 -08:00

65 lines
1.5 KiB
Go

// 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.
package step
import (
"database/sql"
"github.com/drone/drone/store/shared/db"
"github.com/drone/drone/core"
)
// helper function converts the Step structure to a set
// of named query parameters.
func toParams(from *core.Step) map[string]interface{} {
return map[string]interface{}{
"step_id": from.ID,
"step_stage_id": from.StageID,
"step_number": from.Number,
"step_name": from.Name,
"step_status": from.Status,
"step_error": from.Error,
"step_errignore": from.ErrIgnore,
"step_exit_code": from.ExitCode,
"step_started": from.Started,
"step_stopped": from.Stopped,
"step_version": from.Version,
}
}
// helper function scans the sql.Row and copies the column
// values to the destination object.
func scanRow(scanner db.Scanner, dest *core.Step) error {
return scanner.Scan(
&dest.ID,
&dest.StageID,
&dest.Number,
&dest.Name,
&dest.Status,
&dest.Error,
&dest.ErrIgnore,
&dest.ExitCode,
&dest.Started,
&dest.Stopped,
&dest.Version,
)
}
// helper function scans the sql.Row and copies the column
// values to the destination object.
func scanRows(rows *sql.Rows) ([]*core.Step, error) {
defer rows.Close()
steps := []*core.Step{}
for rows.Next() {
step := new(core.Step)
err := scanRow(rows, step)
if err != nil {
return nil, err
}
steps = append(steps, step)
}
return steps, nil
}