mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-07-23 12:51:40 +02:00
Start to extract DB repositories
This commit is contained in:
40
repository/job.go
Normal file
40
repository/job.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
type JobRepository struct {
|
||||
DB *sqlx.DB
|
||||
}
|
||||
|
||||
func (r *JobRepository) JobExists(jobId int64, cluster string, startTime int64) (rows *sql.Rows, err error) {
|
||||
rows, err = r.DB.Query(`SELECT job.id FROM job WHERE job.job_id = ? AND job.cluster = ? AND job.start_time = ?`,
|
||||
jobId, cluster, startTime)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *JobRepository) IdExists(jobId int64) bool {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (r *JobRepository) AddTag(jobId int64, tagId int64) error {
|
||||
_, err := r.DB.Exec(`INSERT INTO jobtag (job_id, tag_id) VALUES (?, ?)`, jobId, tagId)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *JobRepository) TagExists(tagType string, tagName string) (exists bool, tagId int64) {
|
||||
exists = true
|
||||
if err := sq.Select("id").From("tag").
|
||||
Where("tag.tag_type = ?", tagType).Where("tag.tag_name = ?", tagName).
|
||||
RunWith(r.DB).QueryRow().Scan(&tagId); err != nil {
|
||||
exists = false
|
||||
return exists, tagId
|
||||
} else {
|
||||
return exists, tagId
|
||||
}
|
||||
}
|
1
repository/user.go
Normal file
1
repository/user.go
Normal file
@@ -0,0 +1 @@
|
||||
package repository
|
Reference in New Issue
Block a user