mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-19 08:21:01 +00:00
355 lines
5.4 KiB
Go
355 lines
5.4 KiB
Go
package builtin
|
|
|
|
// DO NOT EDIT
|
|
// code generated by go:generate
|
|
|
|
import (
|
|
"database/sql"
|
|
"encoding/json"
|
|
|
|
. "github.com/drone/drone/pkg/types"
|
|
)
|
|
|
|
var _ = json.Marshal
|
|
|
|
// generic database interface, matching both *sql.Db and *sql.Tx
|
|
type buildDB interface {
|
|
Exec(query string, args ...interface{}) (sql.Result, error)
|
|
Query(query string, args ...interface{}) (*sql.Rows, error)
|
|
QueryRow(query string, args ...interface{}) *sql.Row
|
|
}
|
|
|
|
func getBuild(db buildDB, query string, args ...interface{}) (*Build, error) {
|
|
row := db.QueryRow(query, args...)
|
|
return scanBuild(row)
|
|
}
|
|
|
|
func getBuilds(db buildDB, query string, args ...interface{}) ([]*Build, error) {
|
|
rows, err := db.Query(query, args...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
return scanBuilds(rows)
|
|
}
|
|
|
|
func createBuild(db buildDB, query string, v *Build) error {
|
|
var v0 int64
|
|
var v1 string
|
|
var v2 int
|
|
var v3 int
|
|
var v4 int64
|
|
var v5 int64
|
|
var v6 int64
|
|
var v7 int64
|
|
var v8 int64
|
|
var v9 []byte
|
|
v0 = v.CommitID
|
|
v1 = v.State
|
|
v2 = v.ExitCode
|
|
v3 = v.Sequence
|
|
v4 = v.Duration
|
|
v5 = v.Started
|
|
v6 = v.Finished
|
|
v7 = v.Created
|
|
v8 = v.Updated
|
|
v9, _ = json.Marshal(v.Environment)
|
|
|
|
res, err := db.Exec(query,
|
|
&v0,
|
|
&v1,
|
|
&v2,
|
|
&v3,
|
|
&v4,
|
|
&v5,
|
|
&v6,
|
|
&v7,
|
|
&v8,
|
|
&v9,
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
v.ID, err = res.LastInsertId()
|
|
return err
|
|
}
|
|
|
|
func updateBuild(db buildDB, query string, v *Build) error {
|
|
var v0 int64
|
|
var v1 int64
|
|
var v2 string
|
|
var v3 int
|
|
var v4 int
|
|
var v5 int64
|
|
var v6 int64
|
|
var v7 int64
|
|
var v8 int64
|
|
var v9 int64
|
|
var v10 []byte
|
|
v0 = v.ID
|
|
v1 = v.CommitID
|
|
v2 = v.State
|
|
v3 = v.ExitCode
|
|
v4 = v.Sequence
|
|
v5 = v.Duration
|
|
v6 = v.Started
|
|
v7 = v.Finished
|
|
v8 = v.Created
|
|
v9 = v.Updated
|
|
v10, _ = json.Marshal(v.Environment)
|
|
|
|
_, err := db.Exec(query,
|
|
&v1,
|
|
&v2,
|
|
&v3,
|
|
&v4,
|
|
&v5,
|
|
&v6,
|
|
&v7,
|
|
&v8,
|
|
&v9,
|
|
&v10,
|
|
&v0,
|
|
)
|
|
return err
|
|
}
|
|
|
|
func scanBuild(row *sql.Row) (*Build, error) {
|
|
var v0 int64
|
|
var v1 int64
|
|
var v2 string
|
|
var v3 int
|
|
var v4 int
|
|
var v5 int64
|
|
var v6 int64
|
|
var v7 int64
|
|
var v8 int64
|
|
var v9 int64
|
|
var v10 []byte
|
|
|
|
err := row.Scan(
|
|
&v0,
|
|
&v1,
|
|
&v2,
|
|
&v3,
|
|
&v4,
|
|
&v5,
|
|
&v6,
|
|
&v7,
|
|
&v8,
|
|
&v9,
|
|
&v10,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
v := &Build{}
|
|
v.ID = v0
|
|
v.CommitID = v1
|
|
v.State = v2
|
|
v.ExitCode = v3
|
|
v.Sequence = v4
|
|
v.Duration = v5
|
|
v.Started = v6
|
|
v.Finished = v7
|
|
v.Created = v8
|
|
v.Updated = v9
|
|
json.Unmarshal(v10, &v.Environment)
|
|
|
|
return v, nil
|
|
}
|
|
|
|
func scanBuilds(rows *sql.Rows) ([]*Build, error) {
|
|
var err error
|
|
var vv []*Build
|
|
for rows.Next() {
|
|
var v0 int64
|
|
var v1 int64
|
|
var v2 string
|
|
var v3 int
|
|
var v4 int
|
|
var v5 int64
|
|
var v6 int64
|
|
var v7 int64
|
|
var v8 int64
|
|
var v9 int64
|
|
var v10 []byte
|
|
err = rows.Scan(
|
|
&v0,
|
|
&v1,
|
|
&v2,
|
|
&v3,
|
|
&v4,
|
|
&v5,
|
|
&v6,
|
|
&v7,
|
|
&v8,
|
|
&v9,
|
|
&v10,
|
|
)
|
|
if err != nil {
|
|
return vv, err
|
|
}
|
|
|
|
v := &Build{}
|
|
v.ID = v0
|
|
v.CommitID = v1
|
|
v.State = v2
|
|
v.ExitCode = v3
|
|
v.Sequence = v4
|
|
v.Duration = v5
|
|
v.Started = v6
|
|
v.Finished = v7
|
|
v.Created = v8
|
|
v.Updated = v9
|
|
json.Unmarshal(v10, &v.Environment)
|
|
vv = append(vv, v)
|
|
}
|
|
return vv, rows.Err()
|
|
}
|
|
|
|
const stmtBuildSelectList = `
|
|
SELECT
|
|
build_id
|
|
,build_commit_id
|
|
,build_state
|
|
,build_exit_code
|
|
,build_sequence
|
|
,build_duration
|
|
,build_started
|
|
,build_finished
|
|
,build_created
|
|
,build_updated
|
|
,build_environment
|
|
FROM builds
|
|
`
|
|
|
|
const stmtBuildSelectRange = `
|
|
SELECT
|
|
build_id
|
|
,build_commit_id
|
|
,build_state
|
|
,build_exit_code
|
|
,build_sequence
|
|
,build_duration
|
|
,build_started
|
|
,build_finished
|
|
,build_created
|
|
,build_updated
|
|
,build_environment
|
|
FROM builds
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
const stmtBuildSelect = `
|
|
SELECT
|
|
build_id
|
|
,build_commit_id
|
|
,build_state
|
|
,build_exit_code
|
|
,build_sequence
|
|
,build_duration
|
|
,build_started
|
|
,build_finished
|
|
,build_created
|
|
,build_updated
|
|
,build_environment
|
|
FROM builds
|
|
WHERE build_id = ?
|
|
`
|
|
|
|
const stmtBuildSelectBuildCommitId = `
|
|
SELECT
|
|
build_id
|
|
,build_commit_id
|
|
,build_state
|
|
,build_exit_code
|
|
,build_sequence
|
|
,build_duration
|
|
,build_started
|
|
,build_finished
|
|
,build_created
|
|
,build_updated
|
|
,build_environment
|
|
FROM builds
|
|
WHERE build_commit_id = ?
|
|
`
|
|
|
|
const stmtBuildSelectBuildSeq = `
|
|
SELECT
|
|
build_id
|
|
,build_commit_id
|
|
,build_state
|
|
,build_exit_code
|
|
,build_sequence
|
|
,build_duration
|
|
,build_started
|
|
,build_finished
|
|
,build_created
|
|
,build_updated
|
|
,build_environment
|
|
FROM builds
|
|
WHERE build_commit_id = ?
|
|
AND build_sequence = ?
|
|
`
|
|
|
|
const stmtBuildInsert = `
|
|
INSERT INTO builds (
|
|
build_commit_id
|
|
,build_state
|
|
,build_exit_code
|
|
,build_sequence
|
|
,build_duration
|
|
,build_started
|
|
,build_finished
|
|
,build_created
|
|
,build_updated
|
|
,build_environment
|
|
) VALUES (?,?,?,?,?,?,?,?,?,?);
|
|
`
|
|
|
|
const stmtBuildUpdate = `
|
|
UPDATE builds SET
|
|
build_commit_id = ?
|
|
,build_state = ?
|
|
,build_exit_code = ?
|
|
,build_sequence = ?
|
|
,build_duration = ?
|
|
,build_started = ?
|
|
,build_finished = ?
|
|
,build_created = ?
|
|
,build_updated = ?
|
|
,build_environment = ?
|
|
WHERE build_id = ?
|
|
`
|
|
|
|
const stmtBuildDelete = `
|
|
DELETE FROM builds
|
|
WHERE build_id = ?
|
|
`
|
|
|
|
const stmtBuildTable = `
|
|
CREATE TABLE IF NOT EXISTS builds (
|
|
build_id INTEGER PRIMARY KEY AUTOINCREMENT
|
|
,build_commit_id INTEGER
|
|
,build_state VARCHAR
|
|
,build_exit_code INTEGER
|
|
,build_sequence INTEGER
|
|
,build_duration INTEGER
|
|
,build_started INTEGER
|
|
,build_finished INTEGER
|
|
,build_created INTEGER
|
|
,build_updated INTEGER
|
|
,build_environment VARCHAR(2048)
|
|
);
|
|
`
|
|
|
|
const stmtBuildBuildCommitIdIndex = `
|
|
CREATE INDEX IF NOT EXISTS ix_build_commit_id ON builds (build_commit_id);
|
|
`
|
|
|
|
const stmtBuildBuildSeqIndex = `
|
|
CREATE UNIQUE INDEX IF NOT EXISTS ux_build_seq ON builds (build_commit_id,build_sequence);
|
|
`
|