aboutsummaryrefslogtreecommitdiff
path: root/internal/db/watches.go
diff options
context:
space:
mode:
authorJoe Chen <jc@unknwon.io>2022-06-25 18:07:39 +0800
committerGitHub <noreply@github.com>2022-06-25 18:07:39 +0800
commit083c3ee659c6c5542687f3bafae68cbc24dbc90f (patch)
tree0103bf3b5c5ebfccd368a7cb6a425a521fd669d9 /internal/db/watches.go
parent9df4e3ae3c555a86f691f0d78a43834842e77d8b (diff)
db: refactor "action" table to use GORM (#7054)
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
Diffstat (limited to 'internal/db/watches.go')
-rw-r--r--internal/db/watches.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/db/watches.go b/internal/db/watches.go
new file mode 100644
index 00000000..e93a4ab6
--- /dev/null
+++ b/internal/db/watches.go
@@ -0,0 +1,38 @@
+// Copyright 2020 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package db
+
+import (
+ "context"
+
+ "gorm.io/gorm"
+)
+
+// WatchesStore is the persistent interface for watches.
+//
+// NOTE: All methods are sorted in alphabetical order.
+type WatchesStore interface {
+ // ListByRepo returns all watches of the given repository.
+ ListByRepo(ctx context.Context, repoID int64) ([]*Watch, error)
+}
+
+var Watches WatchesStore
+
+var _ WatchesStore = (*watches)(nil)
+
+type watches struct {
+ *gorm.DB
+}
+
+// NewWatchesStore returns a persistent interface for watches with given
+// database connection.
+func NewWatchesStore(db *gorm.DB) WatchesStore {
+ return &watches{DB: db}
+}
+
+func (db *watches) ListByRepo(ctx context.Context, repoID int64) ([]*Watch, error) {
+ var watches []*Watch
+ return watches, db.WithContext(ctx).Where("repo_id = ?", repoID).Find(&watches).Error
+}