aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2024-03-28 02:48:32 +0900
committerMasaya Tojo <masaya@tojo.tokyo>2024-03-28 02:48:50 +0900
commit727d7759e0a733c4575de5431160fbd090371728 (patch)
tree18826c18e097a36c86394c051c98b4776f73fdbe
parentc114d5cedab38a2f6683eabb7c98e9943eecf8bf (diff)
Add source column to articles table.HEADmain
-rw-r--r--db/articles.rkt23
-rw-r--r--entities/article.rkt3
-rw-r--r--readers/article.rkt5
3 files changed, 20 insertions, 11 deletions
diff --git a/db/articles.rkt b/db/articles.rkt
index b549dc9..091bd41 100644
--- a/db/articles.rkt
+++ b/db/articles.rkt
@@ -18,18 +18,18 @@
insert-article)
(define (fetch-article conn article-id)
- (match-let ([(vector timestamp hash title body)
- (query-row conn "SELECT timestamp, hash, title, body FROM diary.articles WHERE article_id = $1" article-id)])
- (make-article article-id (sql-datetime->srfi-date timestamp) hash title body)))
+ (match-let ([(vector timestamp hash source title body)
+ (query-row conn "SELECT timestamp, hash, source, title, body FROM diary.articles WHERE article_id = $1" article-id)])
+ (make-article article-id (sql-datetime->srfi-date timestamp) hash source title body)))
(define (fetch-latest-articles conn limit)
(define article-list
- (for/list ([(article-id timestamp hash title body)
+ (for/list ([(article-id timestamp hash source title body)
(in-query conn "
-SELECT article_id, timestamp, hash, title, body FROM diary.articles ORDER BY timestamp DESC LIMIT $1
+SELECT article_id, timestamp, hash, source, title, body FROM diary.articles ORDER BY timestamp DESC LIMIT $1
"
limit)])
- (make-article article-id (sql-datetime->srfi-date timestamp) hash title body)))
+ (make-article article-id (sql-datetime->srfi-date timestamp) hash source title body)))
(define article-tags
(for/hash ([(article-id l)
(in-query conn
@@ -99,12 +99,13 @@ RETURNING tag_id
(define (insert-article conn article)
(query-exec conn
"
-INSERT INTO diary.articles(article_id, timestamp, hash, title, body)
-VALUES($1, $2, $3, $4, $5)
+INSERT INTO diary.articles(article_id, timestamp, hash, source, title, body)
+VALUES($1, $2, $3, $4, $5, $6)
"
(article-id article)
(srfi-date->sql-timestamp-tz (article-timestamp article))
(article-hash article)
+ (article-source article)
(article-title article)
(article-body article)))
@@ -114,14 +115,16 @@ VALUES($1, $2, $3, $4, $5)
UPDATE diary.articles
SET timestamp = $2,
hash = $3,
- title = $4,
- body = $5
+ source = $4,
+ title = $5,
+ body = $6
WHERE article_id = $1
AND hash <> $3
"
(article-id article)
(srfi-date->sql-timestamp-tz (article-timestamp article))
(article-hash article)
+ (article-source article)
(article-title article)
(article-body article))))
diff --git a/entities/article.rkt b/entities/article.rkt
index 14319d7..4da6cec 100644
--- a/entities/article.rkt
+++ b/entities/article.rkt
@@ -6,6 +6,7 @@
article-id
article-timestamp
article-hash
+ article-source
article-title
article-body
@@ -18,6 +19,7 @@
(struct article ([id : String]
[timestamp : date]
[hash : String]
+ [source : String]
[title : String]
[body : String])
#:type-name Article
@@ -34,6 +36,7 @@
(make-article-with-tags (article-id a)
(article-timestamp a)
(article-hash a)
+ (article-source a)
(article-title a)
(article-body a)
tags))
diff --git a/readers/article.rkt b/readers/article.rkt
index c60de16..2d14639 100644
--- a/readers/article.rkt
+++ b/readers/article.rkt
@@ -27,6 +27,9 @@
(define hash (hash-ref jse 'hash (thunk (k "hash not found"))))
(unless (string? hash) (k "hash must be a string"))
+ (define source (hash-ref jse 'source (thunk (k "source not found"))))
+ (unless (string? source) (k "source must be a string"))
+
(define title (hash-ref jse 'title (thunk (k "title not found"))))
(unless (string? title) (k "title must be a string"))
@@ -37,7 +40,7 @@
(define body (hash-ref jse 'html (thunk (k "html not found"))))
(unless (string? body) (k "html must be a string"))
- (make-article-with-tags id timestamp hash title body tags))))
+ (make-article-with-tags id timestamp hash source title body tags))))
(: read-article (-> Input-Port (U Article-With-Tags EOF)))
(define (read-article in)