1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-11-30 08:06:52 +02:00
woodpecker/model/key.go
2015-09-29 18:21:17 -07:00

47 lines
973 B
Go

package model
import (
"github.com/drone/drone/shared/database"
"github.com/russross/meddler"
)
type Key struct {
ID int64 `json:"-" meddler:"key_id,pk"`
RepoID int64 `json:"-" meddler:"key_repo_id"`
Public string `json:"public" meddler:"key_public"`
Private string `json:"private" meddler:"key_private"`
}
func GetKey(db meddler.DB, repo *Repo) (*Key, error) {
var key = new(Key)
var err = meddler.QueryRow(db, key, database.Rebind(keyQuery), repo.ID)
return key, err
}
func CreateKey(db meddler.DB, key *Key) error {
return meddler.Save(db, keyTable, key)
}
func UpdateKey(db meddler.DB, key *Key) error {
return meddler.Save(db, keyTable, key)
}
func DeleteKey(db meddler.DB, repo *Repo) error {
var _, err = db.Exec(database.Rebind(keyDeleteStmt), repo.ID)
return err
}
const keyTable = "keys"
const keyQuery = `
SELECT *
FROM keys
WHERE key_repo_id=?
LIMIT 1
`
const keyDeleteStmt = `
DELETE FROM keys
WHERE key_repo_id=?
`