(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))