feat(notify): sqlc queries for notifications crud

This commit is contained in:
2026-04-28 22:18:41 +08:00
parent 32e313d5f7
commit f25078dc8c
2 changed files with 134 additions and 9 deletions
@@ -1,2 +1,22 @@
-- name: Ping :one
SELECT 1::int AS ok;
-- 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);
-- 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;
-- name: CountUnreadByUser :one
SELECT COUNT(*)::int FROM notifications WHERE user_id = $1 AND read_at IS NULL;
-- name: MarkRead :exec
UPDATE notifications SET read_at = now()
WHERE id = $1 AND user_id = $2 AND read_at IS NULL;
-- name: MarkAllReadByUser :exec
UPDATE notifications SET read_at = now()
WHERE user_id = $1 AND read_at IS NULL;