mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-19 08:21:01 +00:00
184 lines
2.8 KiB
Go
184 lines
2.8 KiB
Go
package builtin
|
|
|
|
// DO NOT EDIT
|
|
// code generated by go:generate
|
|
|
|
import (
|
|
"database/sql"
|
|
"encoding/json"
|
|
)
|
|
|
|
var _ = json.Marshal
|
|
|
|
// generic database interface, matching both *sql.Db and *sql.Tx
|
|
type agentDB 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 getAgent(db agentDB, query string, args ...interface{}) (*Agent, error) {
|
|
row := db.QueryRow(query, args...)
|
|
return scanAgent(row)
|
|
}
|
|
|
|
func getAgents(db agentDB, query string, args ...interface{}) ([]*Agent, error) {
|
|
rows, err := db.Query(query, args...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
return scanAgents(rows)
|
|
}
|
|
|
|
func createAgent(db agentDB, query string, v *Agent) error {
|
|
var v0 string
|
|
var v1 int64
|
|
v0 = v.Addr
|
|
v1 = v.BuildID
|
|
|
|
res, err := db.Exec(query,
|
|
&v0,
|
|
&v1,
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
v.ID, err = res.LastInsertId()
|
|
return err
|
|
}
|
|
|
|
func updateAgent(db agentDB, query string, v *Agent) error {
|
|
var v0 int64
|
|
var v1 string
|
|
var v2 int64
|
|
v0 = v.ID
|
|
v1 = v.Addr
|
|
v2 = v.BuildID
|
|
|
|
_, err := db.Exec(query,
|
|
&v1,
|
|
&v2,
|
|
&v0,
|
|
)
|
|
return err
|
|
}
|
|
|
|
func scanAgent(row *sql.Row) (*Agent, error) {
|
|
var v0 int64
|
|
var v1 string
|
|
var v2 int64
|
|
|
|
err := row.Scan(
|
|
&v0,
|
|
&v1,
|
|
&v2,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
v := &Agent{}
|
|
v.ID = v0
|
|
v.Addr = v1
|
|
v.BuildID = v2
|
|
|
|
return v, nil
|
|
}
|
|
|
|
func scanAgents(rows *sql.Rows) ([]*Agent, error) {
|
|
var err error
|
|
var vv []*Agent
|
|
for rows.Next() {
|
|
var v0 int64
|
|
var v1 string
|
|
var v2 int64
|
|
err = rows.Scan(
|
|
&v0,
|
|
&v1,
|
|
&v2,
|
|
)
|
|
if err != nil {
|
|
return vv, err
|
|
}
|
|
|
|
v := &Agent{}
|
|
v.ID = v0
|
|
v.Addr = v1
|
|
v.BuildID = v2
|
|
vv = append(vv, v)
|
|
}
|
|
return vv, rows.Err()
|
|
}
|
|
|
|
const stmtAgentSelectList = `
|
|
SELECT
|
|
agent_id
|
|
,agent_addr
|
|
,agent_build_id
|
|
FROM agents
|
|
`
|
|
|
|
const stmtAgentSelectRange = `
|
|
SELECT
|
|
agent_id
|
|
,agent_addr
|
|
,agent_commit_id
|
|
FROM agents
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
const stmtAgentSelect = `
|
|
SELECT
|
|
agent_id
|
|
,agent_addr
|
|
,agent_commit_id
|
|
FROM agents
|
|
WHERE agent_id = ?
|
|
`
|
|
|
|
const stmtAgentSelectAgentCommit = `
|
|
SELECT
|
|
agent_id
|
|
,agent_addr
|
|
,agent_commit_id
|
|
FROM agents
|
|
WHERE agent_commit_id = ?
|
|
`
|
|
|
|
const stmtAgentSelectCount = `
|
|
SELECT count(1)
|
|
FROM agents
|
|
`
|
|
|
|
const stmtAgentInsert = `
|
|
INSERT INTO agents (
|
|
agent_addr
|
|
,agent_commit_id
|
|
) VALUES (?,?);
|
|
`
|
|
|
|
const stmtAgentUpdate = `
|
|
UPDATE agents SET
|
|
agent_addr = ?
|
|
,agent_commit_id = ?
|
|
WHERE agent_id = ?
|
|
`
|
|
|
|
const stmtAgentDelete = `
|
|
DELETE FROM agents
|
|
WHERE agent_id = ?
|
|
`
|
|
|
|
const stmtAgentTable = `
|
|
CREATE TABLE IF NOT EXISTS agents (
|
|
agent_id INTEGER PRIMARY KEY AUTOINCREMENT
|
|
,agent_addr VARCHAR
|
|
,agent_commit_idINTEGER
|
|
);
|
|
`
|
|
|
|
const stmtAgentAgentCommitIndex = `
|
|
CREATE UNIQUE INDEX IF NOT EXISTS ux_agent_commit ON agents (agent_commit_id);
|
|
`
|