woodpecker/pkg/store/builtin/token_sql.go
2015-06-13 16:48:06 -07:00

255 lines
3.8 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 tokenDB 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 getToken(db tokenDB, query string, args ...interface{}) (*Token, error) {
row := db.QueryRow(query, args...)
return scanToken(row)
}
func getTokens(db tokenDB, query string, args ...interface{}) ([]*Token, error) {
rows, err := db.Query(query, args...)
if err != nil {
return nil, err
}
defer rows.Close()
return scanTokens(rows)
}
func createToken(db tokenDB, query string, v *Token) error {
var v0 int64
var v1 string
var v2 string
var v3 int64
var v4 int64
v0 = v.UserID
v1 = v.Kind
v2 = v.Label
v3 = v.Expiry
v4 = v.Issued
res, err := db.Exec(query,
&v0,
&v1,
&v2,
&v3,
&v4,
)
if err != nil {
return err
}
v.ID, err = res.LastInsertId()
return err
}
func updateToken(db tokenDB, query string, v *Token) error {
var v0 int64
var v1 int64
var v2 string
var v3 string
var v4 int64
var v5 int64
v0 = v.ID
v1 = v.UserID
v2 = v.Kind
v3 = v.Label
v4 = v.Expiry
v5 = v.Issued
_, err := db.Exec(query,
&v1,
&v2,
&v3,
&v4,
&v5,
&v0,
)
return err
}
func scanToken(row *sql.Row) (*Token, error) {
var v0 int64
var v1 int64
var v2 string
var v3 string
var v4 int64
var v5 int64
err := row.Scan(
&v0,
&v1,
&v2,
&v3,
&v4,
&v5,
)
if err != nil {
return nil, err
}
v := &Token{}
v.ID = v0
v.UserID = v1
v.Kind = v2
v.Label = v3
v.Expiry = v4
v.Issued = v5
return v, nil
}
func scanTokens(rows *sql.Rows) ([]*Token, error) {
var err error
var vv []*Token
for rows.Next() {
var v0 int64
var v1 int64
var v2 string
var v3 string
var v4 int64
var v5 int64
err = rows.Scan(
&v0,
&v1,
&v2,
&v3,
&v4,
&v5,
)
if err != nil {
return vv, err
}
v := &Token{}
v.ID = v0
v.UserID = v1
v.Kind = v2
v.Label = v3
v.Expiry = v4
v.Issued = v5
vv = append(vv, v)
}
return vv, rows.Err()
}
const stmtTokenSelectList = `
SELECT
token_id
,token_user_id
,token_kind
,token_label
,token_expiry
,token_issued
FROM tokens
`
const stmtTokenSelectRange = `
SELECT
token_id
,token_user_id
,token_kind
,token_label
,token_expiry
,token_issued
FROM tokens
LIMIT ? OFFSET ?
`
const stmtTokenSelect = `
SELECT
token_id
,token_user_id
,token_kind
,token_label
,token_expiry
,token_issued
FROM tokens
WHERE token_id = ?
`
const stmtTokenSelectTokenUserId = `
SELECT
token_id
,token_user_id
,token_kind
,token_label
,token_expiry
,token_issued
FROM tokens
WHERE token_user_id = ?
`
const stmtTokenSelectTokenUserLabel = `
SELECT
token_id
,token_user_id
,token_kind
,token_label
,token_expiry
,token_issued
FROM tokens
WHERE token_user_id = ?
AND token_label = ?
`
const stmtTokenInsert = `
INSERT INTO tokens (
token_user_id
,token_kind
,token_label
,token_expiry
,token_issued
) VALUES (?,?,?,?,?);
`
const stmtTokenUpdate = `
UPDATE tokens SET
token_user_id = ?
,token_kind = ?
,token_label = ?
,token_expiry = ?
,token_issued = ?
WHERE token_id = ?
`
const stmtTokenDelete = `
DELETE FROM tokens
WHERE token_id = ?
`
const stmtTokenTable = `
CREATE TABLE IF NOT EXISTS tokens (
token_id INTEGER PRIMARY KEY AUTOINCREMENT
,token_user_id INTEGER
,token_kind VARCHAR
,token_label VARCHAR
,token_expiry INTEGER
,token_issued INTEGER
);
`
const stmtTokenTokenUserIdIndex = `
CREATE INDEX IF NOT EXISTS ix_token_user_id ON tokens (token_user_id);
`
const stmtTokenTokenUserLabelIndex = `
CREATE UNIQUE INDEX IF NOT EXISTS ux_token_user_label ON tokens (token_user_id,token_label);
`