blob: c2d826debf0978ea96ef641b97408ea94ca56363 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
(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))
|