aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-11-17 22:27:29 +0000
committerChristopher Baines <mail@cbaines.net>2019-11-17 22:27:29 +0000
commit8d23bd896d798db9a6eb18212cddbc5b3d44e487 (patch)
treece7aebfcd1c41ba88f071bc6652baae77739639c
parentbc448be5c8e23fed843ddba6135af3491d001b9b (diff)
downloaddata-service-8d23bd896d798db9a6eb18212cddbc5b3d44e487.tar
data-service-8d23bd896d798db9a6eb18212cddbc5b3d44e487.tar.gz
-rw-r--r--guix-data-service/model/channel-news.scm65
1 files changed, 63 insertions, 2 deletions
diff --git a/guix-data-service/model/channel-news.scm b/guix-data-service/model/channel-news.scm
index 985737d..c2d826d 100644
--- a/guix-data-service/model/channel-news.scm
+++ b/guix-data-service/model/channel-news.scm
@@ -5,6 +5,67 @@
-(define (channel-news-entries->channel-new-entry-ids channel-news-entries)
- )
+(define (channel-news-entries->channel-news-entry-ids conn channel-news-entries)
+ (insert-missing-data-and-return-all-ids
+ conn
+ "channel_news_entries"
+ '("commit" "tag")
+ (map (match-lambda
+ (($ <channel-news-entry> commit tag)
+ (list commit tag)))
+ channel-news-entries)))
+(define (insert-channel-news-entry-text conn text)
+ (insert-missing-data-and-return-all-ids
+ conn
+ "channel_news_entry_text"
+ '("lang" "text")
+ (map (match-lambda
+ ((lang . text)
+ (list lang text)))
+ text)))
+
+(define (insert-channel-news-entries conn channel-news-entries)
+ (define select-channel-news-entries
+ "
+SELECT channel_news_entries.id,
+ channel_news_entries.commit,
+ channel_news_entries.tag,
+ (
+ SELECT ARRAY_AGG(
+ channel_news_entry_titles.channel_news_entry_text_id
+ ORDER BY channel_news_entry_titles.channel_news_entry_text_id
+ )
+ FROM channel_news_entry_titles
+ WHERE channel_news_entry_id = channel_news_entries.id
+ ) AS title_text,
+ (
+ SELECT ARRAY_AGG(
+ channel_news_entry_bodies.channel_news_entry_text_id
+ ORDER BY channel_news_entry_bodies.channel_news_entry_text_id
+ )
+ FROM channel_news_entry_bodies
+ WHERE channel_news_entry_id = channel_news_entries.id
+ ) AS body_text
+FROM channel_news_entries
+ORDER BY id")
+
+ (define existing
+ (exec-query->vhash conn
+ select-channel-news-entries
+ cdr
+ (lambda (result)
+ (string->number (first result)))))
+
+ (map
+ (match-lambda
+ (($ <channel-news-entry> commit tag title body)
+ (let ((title-ids
+ (sort (insert-channel-news-entry-text conn title)
+ <))
+ (body-ids
+ (sort (insert-channel-news-entry-text conn body)
+ <)))
+
+ ))
+ channel-news-entries))