aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/db
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-11-06 04:10:55 +0900
committernsfisis <nsfisis@gmail.com>2025-11-08 05:04:02 +0900
commite0cc2915f22fe74d5be9e8f51d6b73437192e0ba (patch)
treee2e27e3cba8b5e7205732eef7b6df9789e83396f /backend/db
parentba1e0c904f810193f25d4f88cc2bb168f1d625fe (diff)
downloadfeedaka-e0cc2915f22fe74d5be9e8f51d6b73437192e0ba.tar.gz
feedaka-e0cc2915f22fe74d5be9e8f51d6b73437192e0ba.tar.zst
feedaka-e0cc2915f22fe74d5be9e8f51d6b73437192e0ba.zip
feat: Support multi-user
Diffstat (limited to 'backend/db')
-rw-r--r--backend/db/articles.sql.go12
-rw-r--r--backend/db/feeds.sql.go17
-rw-r--r--backend/db/queries/articles.sql4
-rw-r--r--backend/db/queries/feeds.sql4
4 files changed, 21 insertions, 16 deletions
diff --git a/backend/db/articles.sql.go b/backend/db/articles.sql.go
index 7492598..bf6ea1d 100644
--- a/backend/db/articles.sql.go
+++ b/backend/db/articles.sql.go
@@ -184,7 +184,7 @@ SELECT
f.id as feed_id_2, f.url as feed_url, f.title as feed_title, f.is_subscribed as feed_is_subscribed
FROM articles AS a
INNER JOIN feeds AS f ON a.feed_id = f.id
-WHERE a.is_read = 1 AND f.is_subscribed = 1
+WHERE a.is_read = 1 AND f.is_subscribed = 1 AND f.user_id = ?
ORDER BY a.id DESC
LIMIT 100
`
@@ -202,8 +202,8 @@ type GetReadArticlesRow struct {
FeedIsSubscribed int64
}
-func (q *Queries) GetReadArticles(ctx context.Context) ([]GetReadArticlesRow, error) {
- rows, err := q.db.QueryContext(ctx, getReadArticles)
+func (q *Queries) GetReadArticles(ctx context.Context, userID int64) ([]GetReadArticlesRow, error) {
+ rows, err := q.db.QueryContext(ctx, getReadArticles, userID)
if err != nil {
return nil, err
}
@@ -242,7 +242,7 @@ SELECT
f.id as feed_id_2, f.url as feed_url, f.title as feed_title, f.is_subscribed as feed_is_subscribed
FROM articles AS a
INNER JOIN feeds AS f ON a.feed_id = f.id
-WHERE a.is_read = 0 AND f.is_subscribed = 1
+WHERE a.is_read = 0 AND f.is_subscribed = 1 AND f.user_id = ?
ORDER BY a.id DESC
LIMIT 100
`
@@ -260,8 +260,8 @@ type GetUnreadArticlesRow struct {
FeedIsSubscribed int64
}
-func (q *Queries) GetUnreadArticles(ctx context.Context) ([]GetUnreadArticlesRow, error) {
- rows, err := q.db.QueryContext(ctx, getUnreadArticles)
+func (q *Queries) GetUnreadArticles(ctx context.Context, userID int64) ([]GetUnreadArticlesRow, error) {
+ rows, err := q.db.QueryContext(ctx, getUnreadArticles, userID)
if err != nil {
return nil, err
}
diff --git a/backend/db/feeds.sql.go b/backend/db/feeds.sql.go
index 140fa3a..cec228a 100644
--- a/backend/db/feeds.sql.go
+++ b/backend/db/feeds.sql.go
@@ -74,11 +74,16 @@ func (q *Queries) GetFeed(ctx context.Context, id int64) (Feed, error) {
const getFeedByURL = `-- name: GetFeedByURL :one
SELECT id, url, title, fetched_at, is_subscribed, user_id
FROM feeds
-WHERE url = ?
+WHERE url = ? AND user_id = ?
`
-func (q *Queries) GetFeedByURL(ctx context.Context, url string) (Feed, error) {
- row := q.db.QueryRowContext(ctx, getFeedByURL, url)
+type GetFeedByURLParams struct {
+ Url string
+ UserID int64
+}
+
+func (q *Queries) GetFeedByURL(ctx context.Context, arg GetFeedByURLParams) (Feed, error) {
+ row := q.db.QueryRowContext(ctx, getFeedByURL, arg.Url, arg.UserID)
var i Feed
err := row.Scan(
&i.ID,
@@ -94,12 +99,12 @@ func (q *Queries) GetFeedByURL(ctx context.Context, url string) (Feed, error) {
const getFeeds = `-- name: GetFeeds :many
SELECT id, url, title, fetched_at, is_subscribed, user_id
FROM feeds
-WHERE is_subscribed = 1
+WHERE is_subscribed = 1 AND user_id = ?
ORDER BY id
`
-func (q *Queries) GetFeeds(ctx context.Context) ([]Feed, error) {
- rows, err := q.db.QueryContext(ctx, getFeeds)
+func (q *Queries) GetFeeds(ctx context.Context, userID int64) ([]Feed, error) {
+ rows, err := q.db.QueryContext(ctx, getFeeds, userID)
if err != nil {
return nil, err
}
diff --git a/backend/db/queries/articles.sql b/backend/db/queries/articles.sql
index c1feaae..5acdada 100644
--- a/backend/db/queries/articles.sql
+++ b/backend/db/queries/articles.sql
@@ -12,7 +12,7 @@ SELECT
f.id as feed_id_2, f.url as feed_url, f.title as feed_title, f.is_subscribed as feed_is_subscribed
FROM articles AS a
INNER JOIN feeds AS f ON a.feed_id = f.id
-WHERE a.is_read = 0 AND f.is_subscribed = 1
+WHERE a.is_read = 0 AND f.is_subscribed = 1 AND f.user_id = ?
ORDER BY a.id DESC
LIMIT 100;
@@ -22,7 +22,7 @@ SELECT
f.id as feed_id_2, f.url as feed_url, f.title as feed_title, f.is_subscribed as feed_is_subscribed
FROM articles AS a
INNER JOIN feeds AS f ON a.feed_id = f.id
-WHERE a.is_read = 1 AND f.is_subscribed = 1
+WHERE a.is_read = 1 AND f.is_subscribed = 1 AND f.user_id = ?
ORDER BY a.id DESC
LIMIT 100;
diff --git a/backend/db/queries/feeds.sql b/backend/db/queries/feeds.sql
index 9725252..acf36d2 100644
--- a/backend/db/queries/feeds.sql
+++ b/backend/db/queries/feeds.sql
@@ -6,7 +6,7 @@ WHERE id = ?;
-- name: GetFeeds :many
SELECT id, url, title, fetched_at, is_subscribed, user_id
FROM feeds
-WHERE is_subscribed = 1
+WHERE is_subscribed = 1 AND user_id = ?
ORDER BY id;
-- name: CreateFeed :one
@@ -26,7 +26,7 @@ WHERE id = ?;
-- name: GetFeedByURL :one
SELECT id, url, title, fetched_at, is_subscribed, user_id
FROM feeds
-WHERE url = ?;
+WHERE url = ? AND user_id = ?;
-- name: GetFeedsToFetch :many
SELECT id, url, fetched_at, user_id