feat: implement feed agg and browse
This commit is contained in:
+14
-4
@@ -1,18 +1,28 @@
|
||||
-- name: CreateFeed :one
|
||||
INSERT INTO feeds (id, created_at, updated_at, name, url, user_id)
|
||||
INSERT INTO feeds (id, created_at, updated_at, name, url, user_id, last_fetched_at)
|
||||
VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6
|
||||
$6,
|
||||
$7
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetAllFeeds :many
|
||||
SELECT id, created_at, updated_at, name, url, user_id FROM feeds;
|
||||
SELECT id, created_at, updated_at, name, url, user_id, last_fetched_at FROM feeds;
|
||||
|
||||
-- name: GetFeedByUrl :one
|
||||
SELECT id, created_at, updated_at, name, url, user_id FROM feeds
|
||||
SELECT id, created_at, updated_at, name, url, user_id, last_fetched_at FROM feeds
|
||||
WHERE url = $1;
|
||||
|
||||
-- name: GetNextFeedToFetch :one
|
||||
SELECT id, created_at, updated_at, name, url, user_id, last_fetched_at FROM feeds
|
||||
ORDER BY last_fetched_at ASC NULLS FIRST;
|
||||
|
||||
-- name: MarkFeedAsFetched :exec
|
||||
UPDATE feeds
|
||||
SET last_fetched_at = $1
|
||||
WHERE feeds.id = $2;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
-- name: CreatePost :one
|
||||
INSERT INTO posts (id, created_at, updated_at, title, url, description, published_at, feed_id)
|
||||
VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7,
|
||||
$8
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetPostsForUser :many
|
||||
SELECT
|
||||
posts.id,
|
||||
posts.created_at,
|
||||
posts.updated_at,
|
||||
posts.title,
|
||||
posts.url,
|
||||
posts.description,
|
||||
posts.published_at,
|
||||
posts.feed_id,
|
||||
feeds.name as feed_name
|
||||
FROM posts
|
||||
INNER JOIN feeds
|
||||
ON posts.feed_id = feeds.id
|
||||
INNER JOIN follows
|
||||
ON posts.feed_id = follows.feed_id
|
||||
WHERE follows.user_id = $1
|
||||
ORDER BY posts.published_at DESC, posts.title ASC
|
||||
LIMIT $2;
|
||||
@@ -0,0 +1,8 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE feeds
|
||||
ADD COLUMN last_fetched_at TIMESTAMP NULL;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE feeds
|
||||
DROP COLUMN last_fetched_at;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE posts (
|
||||
id UUID PRIMARY KEY,
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
url TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
published_at TIMESTAMP NULL,
|
||||
feed_id UUID NOT NULL,
|
||||
FOREIGN KEY(feed_id) REFERENCES feeds(id) ON DELETE CASCADE,
|
||||
CONSTRAINT unique_url UNIQUE(url)
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE posts;
|
||||
Reference in New Issue
Block a user