Skip to content

Commit 54d46ec

Browse files
committed
db: add new accessors
Add GetTagByName, GetUserByID and GetWebhookByID so callers share the same typed lookups instead of open-coding the equivalent selects. Signed-off-by: Robin Jarry <robin@jarry.cc>
1 parent b383c6e commit 54d46ec

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎pkg/db/tag.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import (
1111
"github.com/uptrace/bun"
1212
)
1313

14+
func (q *Queries) GetTagByName(name string) (*Tag, error) {
15+
var tag Tag
16+
err := q.Select(&tag).Where("name = ?", name).Scan(q.Ctx)
17+
return &tag, err
18+
}
19+
1420
func (q *Queries) LoadPatchTags(patches []Patch) error {
1521
if len(patches) == 0 {
1622
return nil

‎pkg/db/user.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
package db
77

8+
func (q *Queries) GetUserByID(id int) (*User, error) {
9+
var u User
10+
err := q.Select(&u).Where("id = ?", id).Scan(q.Ctx)
11+
return &u, err
12+
}
13+
814
func (q *Queries) GetUserByUsername(username string) (*User, error) {
915
var u User
1016
err := q.DB.NewSelect().Model(&u).

‎pkg/db/webhook.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ func ValidateEvents(events string) error {
3737
return nil
3838
}
3939

40+
func (q *Queries) GetWebhookByID(id int) (*Webhook, error) {
41+
var hook Webhook
42+
err := q.Select(&hook).Where("id = ?", id).Scan(q.Ctx)
43+
return &hook, err
44+
}
45+
4046
func (q *Queries) GetActiveWebhooks(projectID int) ([]Webhook, error) {
4147
var hooks []Webhook
4248
err := q.DB.NewSelect().Model(&hooks).

0 commit comments

Comments
 (0)