#13 - browse articles
This commit is contained in:
22
sql/queries/createPost.sql
Normal file
22
sql/queries/createPost.sql
Normal 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 *;
|
||||
3
sql/queries/getPostsForUser.sql
Normal file
3
sql/queries/getPostsForUser.sql
Normal 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
14
sql/schema/0005_posts.sql
Normal 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;
|
||||
Reference in New Issue
Block a user