#13 - browse articles

This commit is contained in:
2025-03-11 16:08:34 +02:00
parent f561eb4c34
commit 80602bf04f
10 changed files with 265 additions and 1 deletions

View File

@@ -0,0 +1,22 @@
-- name: CreatePost :one
INSERT INTO posts (id, created_at, updated_at, url, title, description, feed_id, published_at)
VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7,
$8
) ON CONFLICT (url) DO UPDATE
SET
id = $1,
created_at = $2,
updated_at = $3,
title = $5,
description = $6,
feed_id = $7,
published_at = $8
WHERE posts.url = $4
RETURNING *;

View File

@@ -0,0 +1,3 @@
-- name: GetPostsForUser :many
SELECT * FROM posts WHERE feed_id IN (SELECT feed_follows.feed_id FROM feed_follows WHERE feed_follows.user_id = $1)
ORDER BY published_at DESC LIMIT $2;

14
sql/schema/0005_posts.sql Normal file
View File

@@ -0,0 +1,14 @@
-- +goose Up
CREATE TABLE posts(
id UUID PRIMARY KEY,
created_at TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP not null,
title VARCHAR(128) not null,
url VARCHAR(512) not null UNIQUE,
description TEXT not null,
published_at TIMESTAMP not null ,
feed_id UUID not null REFERENCES feeds(id) ON DELETE CASCADE
);
-- +goose Down
DROP TABLE posts;