1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-18 08:26:45 +02:00
woodpecker/store/datastore/repos.go

84 lines
1.6 KiB
Go
Raw Normal View History

package datastore
import (
2015-10-22 01:39:43 +02:00
"fmt"
"github.com/drone/drone/model"
"github.com/russross/meddler"
)
func (db *datastore) GetRepo(id int64) (*model.Repo, error) {
var repo = new(model.Repo)
var err = meddler.Load(db, repoTable, repo, id)
return repo, err
}
func (db *datastore) GetRepoName(name string) (*model.Repo, error) {
var repo = new(model.Repo)
var err = meddler.QueryRow(db, repo, rebind(repoNameQuery), name)
return repo, err
}
func (db *datastore) GetRepoListOf(listof []*model.RepoLite) ([]*model.Repo, error) {
2015-10-22 01:39:43 +02:00
var (
repos []*model.Repo
args []interface{}
stmt string
err error
2015-10-22 01:39:43 +02:00
)
switch meddler.Default {
case meddler.PostgreSQL:
stmt, args = toListPosgres(listof)
default:
stmt, args = toList(listof)
}
if len(args) > 0 {
err = meddler.QueryAll(db, &repos, fmt.Sprintf(repoListOfQuery, stmt), args...)
}
return repos, err
}
func (db *datastore) GetRepoCount() (int, error) {
var count int
var err = db.QueryRow(rebind(repoCountQuery)).Scan(&count)
return count, err
}
func (db *datastore) CreateRepo(repo *model.Repo) error {
return meddler.Insert(db, repoTable, repo)
}
func (db *datastore) UpdateRepo(repo *model.Repo) error {
return meddler.Update(db, repoTable, repo)
}
func (db *datastore) DeleteRepo(repo *model.Repo) error {
var _, err = db.Exec(rebind(repoDeleteStmt), repo.ID)
return err
}
const repoTable = "repos"
const repoNameQuery = `
SELECT *
FROM repos
WHERE repo_full_name = ?
LIMIT 1;
`
2015-10-22 01:39:43 +02:00
const repoListOfQuery = `
SELECT *
FROM repos
WHERE repo_full_name IN (%s)
2015-10-22 01:39:43 +02:00
ORDER BY repo_name
`
const repoCountQuery = `
SELECT COUNT(*) FROM repos
`
const repoDeleteStmt = `
DELETE FROM repos
WHERE repo_id = ?
`