From 8d23bd896d798db9a6eb18212cddbc5b3d44e487 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 17 Nov 2019 22:27:29 +0000 Subject: WIP --- guix-data-service/model/channel-news.scm | 65 +++++++++++++++++++++++++++++++- 1 file 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 + (($ 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 + (($ 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)) -- cgit v1.2.3