You've already forked agentic-coding-workflow
127 lines
3.2 KiB
Go
127 lines
3.2 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: notifications.sql
|
|
|
|
package notifysqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const countUnreadByUser = `-- name: CountUnreadByUser :one
|
|
SELECT COUNT(*)::int FROM notifications WHERE user_id = $1 AND read_at IS NULL
|
|
`
|
|
|
|
func (q *Queries) CountUnreadByUser(ctx context.Context, userID pgtype.UUID) (int32, error) {
|
|
row := q.db.QueryRow(ctx, countUnreadByUser, userID)
|
|
var column_1 int32
|
|
err := row.Scan(&column_1)
|
|
return column_1, err
|
|
}
|
|
|
|
const insertNotification = `-- name: InsertNotification :exec
|
|
INSERT INTO notifications (id, user_id, topic, severity, title, body, link, metadata, created_at)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
`
|
|
|
|
type InsertNotificationParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
UserID pgtype.UUID `json:"user_id"`
|
|
Topic string `json:"topic"`
|
|
Severity string `json:"severity"`
|
|
Title string `json:"title"`
|
|
Body string `json:"body"`
|
|
Link *string `json:"link"`
|
|
Metadata []byte `json:"metadata"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
}
|
|
|
|
func (q *Queries) InsertNotification(ctx context.Context, arg InsertNotificationParams) error {
|
|
_, err := q.db.Exec(ctx, insertNotification,
|
|
arg.ID,
|
|
arg.UserID,
|
|
arg.Topic,
|
|
arg.Severity,
|
|
arg.Title,
|
|
arg.Body,
|
|
arg.Link,
|
|
arg.Metadata,
|
|
arg.CreatedAt,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const listNotificationsByUser = `-- name: ListNotificationsByUser :many
|
|
SELECT id, user_id, topic, severity, title, body, link, metadata, read_at, created_at
|
|
FROM notifications
|
|
WHERE user_id = $1
|
|
AND ($2::bool = false OR read_at IS NULL)
|
|
ORDER BY created_at DESC
|
|
LIMIT $3
|
|
`
|
|
|
|
type ListNotificationsByUserParams struct {
|
|
UserID pgtype.UUID `json:"user_id"`
|
|
Column2 bool `json:"column_2"`
|
|
Limit int32 `json:"limit"`
|
|
}
|
|
|
|
func (q *Queries) ListNotificationsByUser(ctx context.Context, arg ListNotificationsByUserParams) ([]Notification, error) {
|
|
rows, err := q.db.Query(ctx, listNotificationsByUser, arg.UserID, arg.Column2, arg.Limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Notification
|
|
for rows.Next() {
|
|
var i Notification
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Topic,
|
|
&i.Severity,
|
|
&i.Title,
|
|
&i.Body,
|
|
&i.Link,
|
|
&i.Metadata,
|
|
&i.ReadAt,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const markAllReadByUser = `-- name: MarkAllReadByUser :exec
|
|
UPDATE notifications SET read_at = now()
|
|
WHERE user_id = $1 AND read_at IS NULL
|
|
`
|
|
|
|
func (q *Queries) MarkAllReadByUser(ctx context.Context, userID pgtype.UUID) error {
|
|
_, err := q.db.Exec(ctx, markAllReadByUser, userID)
|
|
return err
|
|
}
|
|
|
|
const markRead = `-- name: MarkRead :exec
|
|
UPDATE notifications SET read_at = now()
|
|
WHERE id = $1 AND user_id = $2 AND read_at IS NULL
|
|
`
|
|
|
|
type MarkReadParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
UserID pgtype.UUID `json:"user_id"`
|
|
}
|
|
|
|
func (q *Queries) MarkRead(ctx context.Context, arg MarkReadParams) error {
|
|
_, err := q.db.Exec(ctx, markRead, arg.ID, arg.UserID)
|
|
return err
|
|
}
|