harness-drone/pkg/store/builtin/user_sql.go

282 lines
3.9 KiB
Go
Raw Normal View History

2015-06-13 23:48:06 +00:00
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 userDB 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 getUser(db userDB, query string, args ...interface{}) (*User, error) {
row := db.QueryRow(query, args...)
return scanUser(row)
}
func getUsers(db userDB, query string, args ...interface{}) ([]*User, error) {
rows, err := db.Query(query, args...)
if err != nil {
return nil, err
}
defer rows.Close()
return scanUsers(rows)
}
func createUser(db userDB, query string, v *User) error {
var v0 string
var v1 string
var v2 string
var v3 string
var v4 string
2015-06-18 23:37:40 +00:00
var v5 bool
2015-06-13 23:48:06 +00:00
var v6 bool
v0 = v.Login
v1 = v.Token
v2 = v.Secret
2015-06-18 23:37:40 +00:00
v3 = v.Email
v4 = v.Avatar
v5 = v.Active
2015-06-13 23:48:06 +00:00
v6 = v.Admin
res, err := db.Exec(query,
&v0,
&v1,
&v2,
&v3,
&v4,
&v5,
&v6,
)
if err != nil {
return err
}
v.ID, err = res.LastInsertId()
return err
}
func updateUser(db userDB, query string, v *User) error {
var v0 int64
var v1 string
var v2 string
var v3 string
var v4 string
var v5 string
2015-06-18 23:37:40 +00:00
var v6 bool
2015-06-13 23:48:06 +00:00
var v7 bool
v0 = v.ID
v1 = v.Login
v2 = v.Token
v3 = v.Secret
2015-06-18 23:37:40 +00:00
v4 = v.Email
v5 = v.Avatar
v6 = v.Active
2015-06-13 23:48:06 +00:00
v7 = v.Admin
_, err := db.Exec(query,
&v1,
&v2,
&v3,
&v4,
&v5,
&v6,
&v7,
&v0,
)
return err
}
func scanUser(row *sql.Row) (*User, error) {
var v0 int64
var v1 string
var v2 string
var v3 string
var v4 string
var v5 string
2015-06-18 23:37:40 +00:00
var v6 bool
2015-06-13 23:48:06 +00:00
var v7 bool
err := row.Scan(
&v0,
&v1,
&v2,
&v3,
&v4,
&v5,
&v6,
&v7,
)
if err != nil {
return nil, err
}
v := &User{}
v.ID = v0
v.Login = v1
v.Token = v2
v.Secret = v3
2015-06-18 23:37:40 +00:00
v.Email = v4
v.Avatar = v5
v.Active = v6
2015-06-13 23:48:06 +00:00
v.Admin = v7
return v, nil
}
func scanUsers(rows *sql.Rows) ([]*User, error) {
var err error
var vv []*User
for rows.Next() {
var v0 int64
var v1 string
var v2 string
var v3 string
var v4 string
var v5 string
2015-06-18 23:37:40 +00:00
var v6 bool
2015-06-13 23:48:06 +00:00
var v7 bool
err = rows.Scan(
&v0,
&v1,
&v2,
&v3,
&v4,
&v5,
&v6,
&v7,
)
if err != nil {
return vv, err
}
v := &User{}
v.ID = v0
v.Login = v1
v.Token = v2
v.Secret = v3
2015-06-18 23:37:40 +00:00
v.Email = v4
v.Avatar = v5
v.Active = v6
2015-06-13 23:48:06 +00:00
v.Admin = v7
vv = append(vv, v)
}
return vv, rows.Err()
}
const stmtUserSelectList = `
SELECT
user_id
,user_login
,user_token
,user_secret
,user_email
2015-06-18 23:37:40 +00:00
,user_avatar
2015-06-13 23:48:06 +00:00
,user_active
2015-06-18 23:37:40 +00:00
,user_admin
2015-06-13 23:48:06 +00:00
FROM users
`
const stmtUserSelectRange = `
SELECT
user_id
,user_login
,user_token
,user_secret
,user_email
2015-06-18 23:37:40 +00:00
,user_avatar
2015-06-13 23:48:06 +00:00
,user_active
2015-06-18 23:37:40 +00:00
,user_admin
2015-06-13 23:48:06 +00:00
FROM users
LIMIT ? OFFSET ?
`
const stmtUserSelect = `
SELECT
user_id
,user_login
,user_token
,user_secret
,user_email
2015-06-18 23:37:40 +00:00
,user_avatar
2015-06-13 23:48:06 +00:00
,user_active
2015-06-18 23:37:40 +00:00
,user_admin
2015-06-13 23:48:06 +00:00
FROM users
WHERE user_id = ?
`
const stmtUserSelectUserLogin = `
SELECT
user_id
,user_login
,user_token
,user_secret
,user_email
2015-06-18 23:37:40 +00:00
,user_avatar
2015-06-13 23:48:06 +00:00
,user_active
2015-06-18 23:37:40 +00:00
,user_admin
2015-06-13 23:48:06 +00:00
FROM users
WHERE user_login = ?
`
const stmtUserSelectCount = `
SELECT count(1)
FROM users
`
const stmtUserInsert = `
INSERT INTO users (
user_login
,user_token
,user_secret
,user_email
2015-06-18 23:37:40 +00:00
,user_avatar
2015-06-13 23:48:06 +00:00
,user_active
2015-06-18 23:37:40 +00:00
,user_admin
) VALUES (?,?,?,?,?,?,?);
2015-06-13 23:48:06 +00:00
`
const stmtUserUpdate = `
UPDATE users SET
user_login = ?
,user_token = ?
,user_secret = ?
,user_email = ?
2015-06-18 23:37:40 +00:00
,user_avatar = ?
2015-06-13 23:48:06 +00:00
,user_active = ?
2015-06-18 23:37:40 +00:00
,user_admin = ?
2015-06-13 23:48:06 +00:00
WHERE user_id = ?
`
const stmtUserDelete = `
DELETE FROM users
WHERE user_id = ?
`
const stmtUserTable = `
CREATE TABLE IF NOT EXISTS users (
2015-06-18 23:37:40 +00:00
user_id INTEGER PRIMARY KEY AUTOINCREMENT
,user_login VARCHAR
,user_token VARCHAR
2015-06-13 23:48:06 +00:00
,user_secret VARCHAR
2015-06-18 23:37:40 +00:00
,user_email VARCHAR
,user_avatar VARCHAR
2015-06-13 23:48:06 +00:00
,user_active BOOLEAN
2015-06-18 23:37:40 +00:00
,user_admin BOOLEAN
2015-06-13 23:48:06 +00:00
);
`
const stmtUserUserLoginIndex = `
CREATE UNIQUE INDEX IF NOT EXISTS ux_user_login ON users (user_login);
`