aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-02-15 18:23:04 +0000
committerChristopher Baines <mail@cbaines.net>2020-02-15 18:23:04 +0000
commita6e19a4102f5160d6fb60f851474fb09dc83742d (patch)
tree46643f69ec6f0ab6b75f923968e441e9c8740492
parent36254f98e366657189b435af0bf130c142ceb73a (diff)
downloaddata-service-a6e19a4102f5160d6fb60f851474fb09dc83742d.tar
data-service-a6e19a4102f5160d6fb60f851474fb09dc83742d.tar.gz
Avoid an error when there are no references to insert
-rw-r--r--guix-data-service/model/nar.scm39
1 files changed, 20 insertions, 19 deletions
diff --git a/guix-data-service/model/nar.scm b/guix-data-service/model/nar.scm
index 7e27034..4c5d070 100644
--- a/guix-data-service/model/nar.scm
+++ b/guix-data-service/model/nar.scm
@@ -60,27 +60,28 @@
'(store_path hash_algorithm hash size system deriver)
data)))
- (exec-query
- conn
- (string-append
- "
+ (let ((reference-data
+ (concatenate
+ (map (lambda (nar-id narinfo)
+ (map (lambda (reference)
+ (simple-format
+ #f
+ "(~A, ~A)"
+ nar-id
+ (quote-string reference)))
+ (narinfo-references narinfo)))
+ nar-ids
+ narinfos))))
+ (unless (null? reference-data)
+ (exec-query
+ conn
+ (string-append
+ "
INSERT INTO nar_references (nar_id, reference)
VALUES "
- (string-join
- (concatenate
- (map (lambda (nar-id narinfo)
- (map (lambda (reference)
- (simple-format
- #f
- "(~A, ~A)"
- nar-id
- (quote-string reference)))
- (narinfo-references narinfo)))
- nar-ids
- narinfos))
- ", ")
- "
-ON CONFLICT DO NOTHING"))
+ (string-join reference-data ", ")
+ "
+ON CONFLICT DO NOTHING"))))
(exec-query
conn