woodpecker/pkg/store/builtin/build.go

48 lines
1.2 KiB
Go
Raw Normal View History

package builtin
import (
2015-06-13 23:48:06 +00:00
"database/sql"
"time"
2015-04-29 22:26:22 +00:00
2015-06-13 23:48:06 +00:00
"github.com/drone/drone/pkg/types"
)
type Buildstore struct {
2015-06-13 23:48:06 +00:00
*sql.DB
}
2015-06-13 23:48:06 +00:00
func NewBuildstore(db *sql.DB) *Buildstore {
return &Buildstore{db}
}
// Build returns a build by ID.
2015-06-13 23:48:06 +00:00
func (db *Buildstore) Build(id int64) (*types.Build, error) {
return getBuild(db, rebind(stmtBuildSelect), id)
}
// BuildSeq returns a build by sequence number.
2015-06-13 23:48:06 +00:00
func (db *Buildstore) BuildSeq(commit *types.Commit, seq int) (*types.Build, error) {
return getBuild(db, rebind(stmtBuildSelectBuildSeq), commit.ID, seq)
}
2015-04-25 00:19:48 +00:00
// BuildList returns a list of all commit builds
2015-06-13 23:48:06 +00:00
func (db *Buildstore) BuildList(commit *types.Commit) ([]*types.Build, error) {
return getBuilds(db, rebind(stmtBuildSelectBuildCommitId), commit.ID)
2015-04-29 22:26:22 +00:00
}
// SetBuild updates an existing build.
2015-06-13 23:48:06 +00:00
func (db *Buildstore) SetBuild(build *types.Build) error {
build.Updated = time.Now().UTC().Unix()
2015-06-13 23:48:06 +00:00
return updateBuild(db, rebind(stmtBuildUpdate), build)
}
// AddBuild inserts a build.
func (db *Buildstore) AddBuild(build *types.Build) error {
build.Created = time.Now().UTC().Unix()
build.Updated = time.Now().UTC().Unix()
return createBuild(db, rebind(stmtBuildInsert), build)
}
// Build table name in database.
const buildTable = "builds"