Files
gator/sql/queries/follows.sql
T
Stevan Freeborn f51b1b941a feat: added new commands
- added follow command
- added unfollow command
- following command
- introduced logged in user middleware
2026-08-02 07:49:57 -05:00

31 lines
666 B
SQL

-- name: CreateFollow :one
WITH inserted_follow as (
INSERT INTO follows (id, created_at, updated_at, feed_id, user_id)
VALUES (
$1,
$2,
$3,
$4,
$5
)
RETURNING *
)
SELECT inserted_follow.*,
feeds.name as feed_name,
users.name as user_name
FROM inserted_follow
INNER JOIN users
ON inserted_follow.user_id = users.id
INNER JOIN feeds
ON inserted_follow.feed_id = feeds.id;
-- name: GetFollowsForUser :many
SELECT follows.*, feeds.name as feed_name FROM follows
INNER JOIN feeds
ON follows.feed_id = feeds.id
WHERE follows.user_id = $1;
-- name: DeleteFollowForUser :exec
DELETE FROM follows
WHERE feed_id = $1 AND user_id = $2;