Go · 1904 bytes Raw Blame History
1 // Code generated by sqlc. DO NOT EDIT.
2 // versions:
3 // sqlc v1.31.1
4 // source: user_notification_prefs.sql
5
6 package usersdb
7
8 import (
9 "context"
10 )
11
12 const deleteUserNotificationPref = `-- name: DeleteUserNotificationPref :exec
13 DELETE FROM user_notification_prefs WHERE user_id = $1 AND key = $2
14 `
15
16 type DeleteUserNotificationPrefParams struct {
17 UserID int64
18 Key string
19 }
20
21 func (q *Queries) DeleteUserNotificationPref(ctx context.Context, db DBTX, arg DeleteUserNotificationPrefParams) error {
22 _, err := db.Exec(ctx, deleteUserNotificationPref, arg.UserID, arg.Key)
23 return err
24 }
25
26 const listUserNotificationPrefs = `-- name: ListUserNotificationPrefs :many
27
28 SELECT user_id, key, value, updated_at
29 FROM user_notification_prefs
30 WHERE user_id = $1
31 ORDER BY key
32 `
33
34 // SPDX-License-Identifier: AGPL-3.0-or-later
35 func (q *Queries) ListUserNotificationPrefs(ctx context.Context, db DBTX, userID int64) ([]UserNotificationPref, error) {
36 rows, err := db.Query(ctx, listUserNotificationPrefs, userID)
37 if err != nil {
38 return nil, err
39 }
40 defer rows.Close()
41 items := []UserNotificationPref{}
42 for rows.Next() {
43 var i UserNotificationPref
44 if err := rows.Scan(
45 &i.UserID,
46 &i.Key,
47 &i.Value,
48 &i.UpdatedAt,
49 ); err != nil {
50 return nil, err
51 }
52 items = append(items, i)
53 }
54 if err := rows.Err(); err != nil {
55 return nil, err
56 }
57 return items, nil
58 }
59
60 const upsertUserNotificationPref = `-- name: UpsertUserNotificationPref :exec
61 INSERT INTO user_notification_prefs (user_id, key, value)
62 VALUES ($1, $2, $3)
63 ON CONFLICT (user_id, key) DO UPDATE
64 SET value = EXCLUDED.value
65 `
66
67 type UpsertUserNotificationPrefParams struct {
68 UserID int64
69 Key string
70 Value []byte
71 }
72
73 func (q *Queries) UpsertUserNotificationPref(ctx context.Context, db DBTX, arg UpsertUserNotificationPrefParams) error {
74 _, err := db.Exec(ctx, upsertUserNotificationPref, arg.UserID, arg.Key, arg.Value)
75 return err
76 }
77