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-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-06-19 00:36:52 +00:00
|
|
|
type Jobstore struct {
|
2015-06-13 23:48:06 +00:00
|
|
|
*sql.DB
|
2015-04-07 08:20:55 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 00:36:52 +00:00
|
|
|
func NewJobstore(db *sql.DB) *Jobstore {
|
|
|
|
return &Jobstore{db}
|
2015-04-07 08:20:55 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 00:36:52 +00:00
|
|
|
// Job returns a Job by ID.
|
|
|
|
func (db *Jobstore) Job(id int64) (*types.Job, error) {
|
|
|
|
return getJob(db, rebind(stmtJobSelect), id)
|
2015-04-07 08:20:55 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 00:36:52 +00:00
|
|
|
// JobNumber returns a job by sequence number.
|
|
|
|
func (db *Jobstore) JobNumber(commit *types.Commit, seq int) (*types.Job, error) {
|
|
|
|
return getJob(db, rebind(stmtJobSelectBuildNumber), commit.ID, seq)
|
2015-04-16 06:45:24 +00:00
|
|
|
}
|
2015-04-25 00:19:48 +00:00
|
|
|
|
2015-06-19 00:36:52 +00:00
|
|
|
// JobList returns a list of all build jobs
|
|
|
|
func (db *Jobstore) JobList(commit *types.Commit) ([]*types.Job, error) {
|
|
|
|
return getJobs(db, rebind(stmtJobSelectJobBuildId), commit.ID)
|
2015-04-29 22:26:22 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 00:36:52 +00:00
|
|
|
// SetJob updates an existing build job.
|
|
|
|
func (db *Jobstore) SetJob(job *types.Job) error {
|
|
|
|
return updateJob(db, rebind(stmtJobUpdate), job)
|
2015-06-13 23:48:06 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 00:36:52 +00:00
|
|
|
// AddJob inserts a build job.
|
|
|
|
func (db *Jobstore) AddJob(job *types.Job) error {
|
|
|
|
return createJob(db, rebind(stmtJobInsert), job)
|
2015-05-11 07:45:31 +00:00
|
|
|
}
|