mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-26 02:10:31 +00:00
37 lines
779 B
Go
37 lines
779 B
Go
package datastore
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/drone/drone/model"
|
|
"github.com/russross/meddler"
|
|
)
|
|
|
|
type keystore struct {
|
|
*sql.DB
|
|
}
|
|
|
|
func (db *keystore) Get(repo *model.Repo) (*model.Key, error) {
|
|
var key = new(model.Key)
|
|
var err = meddler.QueryRow(db, key, rebind(keyQuery), repo.ID)
|
|
return key, err
|
|
}
|
|
|
|
func (db *keystore) Create(key *model.Key) error {
|
|
return meddler.Save(db, keyTable, key)
|
|
}
|
|
|
|
func (db *keystore) Update(key *model.Key) error {
|
|
return meddler.Save(db, keyTable, key)
|
|
}
|
|
|
|
func (db *keystore) Delete(key *model.Key) error {
|
|
var _, err = db.Exec(rebind(keyDeleteStmt), key.ID)
|
|
return err
|
|
}
|
|
|
|
const keyTable = "keys"
|
|
|
|
const keyQuery = "SELECT * FROM `keys` WHERE key_repo_id=? LIMIT 1"
|
|
|
|
const keyDeleteStmt = "DELETE FROM `keys` WHERE key_id=?"
|