diff --git a/basil/src/main/sqldelight/com/jocmp/basil/db/article_statuses.sq b/basil/src/main/sqldelight/com/jocmp/basil/db/article_statuses.sq index 469b5d79..b9a1fc06 100644 --- a/basil/src/main/sqldelight/com/jocmp/basil/db/article_statuses.sq +++ b/basil/src/main/sqldelight/com/jocmp/basil/db/article_statuses.sq @@ -1,9 +1,10 @@ import kotlin.Boolean; CREATE TABLE article_statuses ( - id INTEGER NOT NULL PRIMARY KEY, - article_id INTEGER NOT NULL REFERENCES articles(id), + feed_id INTEGER NOT NULL REFERENCES feeds(id), + external_id INTEGER NOT NULL REFERENCES articles(external_id), read INTEGER AS Boolean DEFAULT 0, starred INTEGER AS Boolean DEFAULT 0, - arrived_at INTEGER NOT NULL + arrived_at INTEGER NOT NULL, + PRIMARY KEY (feed_id, external_id) ); diff --git a/basil/src/main/sqldelight/com/jocmp/basil/db/articles.sq b/basil/src/main/sqldelight/com/jocmp/basil/db/articles.sq index 97b857a2..124d3ef2 100644 --- a/basil/src/main/sqldelight/com/jocmp/basil/db/articles.sq +++ b/basil/src/main/sqldelight/com/jocmp/basil/db/articles.sq @@ -15,7 +15,7 @@ CREATE UNIQUE INDEX articles_external_id_index ON articles(external_id); countByStatus: SELECT COUNT(*) FROM articles -JOIN article_statuses ON articles.id = article_statuses.article_id +JOIN article_statuses ON articles.external_id = article_statuses.external_id WHERE article_statuses.read IN :read AND article_statuses.starred IN :starred; @@ -26,7 +26,7 @@ SELECT article_statuses.starred, article_statuses.read FROM articles -JOIN article_statuses ON articles.id = article_statuses.article_id +JOIN article_statuses ON articles.external_id = article_statuses.external_id AND article_statuses.feed_id = articles.feed_id AND article_statuses.read IN :read AND article_statuses.starred IN :starred ORDER BY article_statuses.arrived_at DESC @@ -35,8 +35,8 @@ LIMIT :limit OFFSET :offset; countByFeeds: SELECT COUNT(*) FROM articles -JOIN article_statuses ON articles.id = article_statuses.article_id -WHERE feed_id IN :feedIDs +JOIN article_statuses ON articles.external_id = article_statuses.external_id AND article_statuses.feed_id = articles.feed_id +WHERE articles.feed_id IN :feedIDs AND article_statuses.read IN :read AND article_statuses.starred IN :starred; @@ -47,8 +47,8 @@ SELECT article_statuses.starred, article_statuses.read FROM articles -JOIN article_statuses ON articles.id = article_statuses.article_id -WHERE feed_id IN :feedIDs +JOIN article_statuses ON articles.external_id = article_statuses.external_id AND article_statuses.feed_id = articles.feed_id +WHERE articles.feed_id IN :feedIDs AND article_statuses.read IN :read AND article_statuses.starred IN :starred ORDER BY article_statuses.arrived_at DESC @@ -61,7 +61,7 @@ SELECT article_statuses.starred, article_statuses.read FROM articles -JOIN article_statuses ON articles.id = article_statuses.article_id +JOIN article_statuses ON articles.external_id = article_statuses.external_id AND article_statuses.feed_id = articles.feed_id WHERE articles.id = :articleID LIMIT 1; @@ -77,16 +77,24 @@ create { published_at ) VALUES ( - ?, - ?, - ?, - ?, - ?, - ?, - ?, - ? + :feed_id, + :external_id, + :title, + :content_html, + :url, + :summary, + :image_url, + :published_at ); - INSERT OR IGNORE INTO article_statuses(article_id, arrived_at) - VALUES (last_insert_rowid(), ?); + INSERT OR IGNORE INTO article_statuses( + feed_id, + external_id, + arrived_at + ) + VALUES ( + :feed_id, + :external_id, + :arrived_at + ); }