2015-05-01 04:08:42 +00:00
|
|
|
package builtin
|
2015-04-07 08:20:55 +00:00
|
|
|
|
|
|
|
import (
|
2015-06-13 23:48:06 +00:00
|
|
|
"database/sql"
|
2015-04-23 19:39:36 +00:00
|
|
|
"time"
|
2015-04-29 22:26:22 +00:00
|
|
|
|
2015-06-13 23:48:06 +00:00
|
|
|
"github.com/drone/drone/pkg/types"
|
2015-04-07 08:20:55 +00:00
|
|
|
)
|
|
|
|
|
2015-05-11 07:45:31 +00:00
|
|
|
type Buildstore struct {
|
2015-06-13 23:48:06 +00:00
|
|
|
*sql.DB
|
2015-04-07 08:20:55 +00:00
|
|
|
}
|
|
|
|
|
2015-06-13 23:48:06 +00:00
|
|
|
func NewBuildstore(db *sql.DB) *Buildstore {
|
2015-05-11 07:45:31 +00:00
|
|
|
return &Buildstore{db}
|
2015-04-07 08:20:55 +00:00
|
|
|
}
|
|
|
|
|
2015-05-11 07:45:31 +00:00
|
|
|
// 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)
|
2015-04-07 08:20:55 +00:00
|
|
|
}
|
|
|
|
|
2015-05-11 07:45:31 +00:00
|
|
|
// 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-16 06:45:24 +00:00
|
|
|
}
|
2015-04-25 00:19:48 +00:00
|
|
|
|
2015-05-11 07:45:31 +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
|
|
|
}
|
|
|
|
|
2015-05-11 07:45:31 +00:00
|
|
|
// SetBuild updates an existing build.
|
2015-06-13 23:48:06 +00:00
|
|
|
func (db *Buildstore) SetBuild(build *types.Build) error {
|
2015-05-11 07:45:31 +00:00
|
|
|
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)
|
2015-05-11 07:45:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build table name in database.
|
|
|
|
const buildTable = "builds"
|