summaryrefslogtreecommitdiff
path: root/internal/db/bundb/notification.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/bundb/notification.go')
-rw-r--r--internal/db/bundb/notification.go50
1 files changed, 25 insertions, 25 deletions
diff --git a/internal/db/bundb/notification.go b/internal/db/bundb/notification.go
index 277a935fd..b0757fb1e 100644
--- a/internal/db/bundb/notification.go
+++ b/internal/db/bundb/notification.go
@@ -31,19 +31,19 @@ import (
)
type notificationDB struct {
- conn *DBConn
+ db *WrappedDB
state *state.State
}
-func (n *notificationDB) GetNotificationByID(ctx context.Context, id string) (*gtsmodel.Notification, db.Error) {
+func (n *notificationDB) GetNotificationByID(ctx context.Context, id string) (*gtsmodel.Notification, error) {
return n.state.Caches.GTS.Notification().Load("ID", func() (*gtsmodel.Notification, error) {
var notif gtsmodel.Notification
- q := n.conn.NewSelect().
+ q := n.db.NewSelect().
Model(&notif).
Where("? = ?", bun.Ident("notification.id"), id)
if err := q.Scan(ctx); err != nil {
- return nil, n.conn.ProcessError(err)
+ return nil, n.db.ProcessError(err)
}
return &notif, nil
@@ -56,11 +56,11 @@ func (n *notificationDB) GetNotification(
targetAccountID string,
originAccountID string,
statusID string,
-) (*gtsmodel.Notification, db.Error) {
+) (*gtsmodel.Notification, error) {
return n.state.Caches.GTS.Notification().Load("NotificationType.TargetAccountID.OriginAccountID.StatusID", func() (*gtsmodel.Notification, error) {
var notif gtsmodel.Notification
- q := n.conn.NewSelect().
+ q := n.db.NewSelect().
Model(&notif).
Where("? = ?", bun.Ident("notification_type"), notificationType).
Where("? = ?", bun.Ident("target_account_id"), targetAccountID).
@@ -68,7 +68,7 @@ func (n *notificationDB) GetNotification(
Where("? = ?", bun.Ident("status_id"), statusID)
if err := q.Scan(ctx); err != nil {
- return nil, n.conn.ProcessError(err)
+ return nil, n.db.ProcessError(err)
}
return &notif, nil
@@ -83,7 +83,7 @@ func (n *notificationDB) GetAccountNotifications(
minID string,
limit int,
excludeTypes []string,
-) ([]*gtsmodel.Notification, db.Error) {
+) ([]*gtsmodel.Notification, error) {
// Ensure reasonable
if limit < 0 {
limit = 0
@@ -95,7 +95,7 @@ func (n *notificationDB) GetAccountNotifications(
frontToBack = true
)
- q := n.conn.
+ q := n.db.
NewSelect().
TableExpr("? AS ?", bun.Ident("notifications"), bun.Ident("notification")).
Column("notification.id")
@@ -140,7 +140,7 @@ func (n *notificationDB) GetAccountNotifications(
}
if err := q.Scan(ctx, &notifIDs); err != nil {
- return nil, n.conn.ProcessError(err)
+ return nil, n.db.ProcessError(err)
}
if len(notifIDs) == 0 {
@@ -174,12 +174,12 @@ func (n *notificationDB) GetAccountNotifications(
func (n *notificationDB) PutNotification(ctx context.Context, notif *gtsmodel.Notification) error {
return n.state.Caches.GTS.Notification().Store(notif, func() error {
- _, err := n.conn.NewInsert().Model(notif).Exec(ctx)
- return n.conn.ProcessError(err)
+ _, err := n.db.NewInsert().Model(notif).Exec(ctx)
+ return n.db.ProcessError(err)
})
}
-func (n *notificationDB) DeleteNotificationByID(ctx context.Context, id string) db.Error {
+func (n *notificationDB) DeleteNotificationByID(ctx context.Context, id string) error {
defer n.state.Caches.GTS.Notification().Invalidate("ID", id)
// Load notif into cache before attempting a delete,
@@ -195,21 +195,21 @@ func (n *notificationDB) DeleteNotificationByID(ctx context.Context, id string)
}
// Finally delete notif from DB.
- _, err = n.conn.NewDelete().
+ _, err = n.db.NewDelete().
TableExpr("? AS ?", bun.Ident("notifications"), bun.Ident("notification")).
Where("? = ?", bun.Ident("notification.id"), id).
Exec(ctx)
- return n.conn.ProcessError(err)
+ return n.db.ProcessError(err)
}
-func (n *notificationDB) DeleteNotifications(ctx context.Context, types []string, targetAccountID string, originAccountID string) db.Error {
+func (n *notificationDB) DeleteNotifications(ctx context.Context, types []string, targetAccountID string, originAccountID string) error {
if targetAccountID == "" && originAccountID == "" {
return errors.New("DeleteNotifications: one of targetAccountID or originAccountID must be set")
}
var notifIDs []string
- q := n.conn.
+ q := n.db.
NewSelect().
Column("id").
Table("notifications")
@@ -227,7 +227,7 @@ func (n *notificationDB) DeleteNotifications(ctx context.Context, types []string
}
if _, err := q.Exec(ctx, &notifIDs); err != nil {
- return n.conn.ProcessError(err)
+ return n.db.ProcessError(err)
}
defer func() {
@@ -248,24 +248,24 @@ func (n *notificationDB) DeleteNotifications(ctx context.Context, types []string
}
// Finally delete all from DB.
- _, err := n.conn.NewDelete().
+ _, err := n.db.NewDelete().
Table("notifications").
Where("? IN (?)", bun.Ident("id"), bun.In(notifIDs)).
Exec(ctx)
- return n.conn.ProcessError(err)
+ return n.db.ProcessError(err)
}
-func (n *notificationDB) DeleteNotificationsForStatus(ctx context.Context, statusID string) db.Error {
+func (n *notificationDB) DeleteNotificationsForStatus(ctx context.Context, statusID string) error {
var notifIDs []string
- q := n.conn.
+ q := n.db.
NewSelect().
Column("id").
Table("notifications").
Where("? = ?", bun.Ident("status_id"), statusID)
if _, err := q.Exec(ctx, &notifIDs); err != nil {
- return n.conn.ProcessError(err)
+ return n.db.ProcessError(err)
}
defer func() {
@@ -286,9 +286,9 @@ func (n *notificationDB) DeleteNotificationsForStatus(ctx context.Context, statu
}
// Finally delete all from DB.
- _, err := n.conn.NewDelete().
+ _, err := n.db.NewDelete().
Table("notifications").
Where("? IN (?)", bun.Ident("id"), bun.In(notifIDs)).
Exec(ctx)
- return n.conn.ProcessError(err)
+ return n.db.ProcessError(err)
}