From e38bddcae542bad878a4e9169fcf40fec72a1134 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sat, 24 Apr 2021 05:58:48 +0100 Subject: Reformat a couple of package related queries --- guix-data-service/model/package.scm | 62 ++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/guix-data-service/model/package.scm b/guix-data-service/model/package.scm index 2d8d21b..6f7d204 100644 --- a/guix-data-service/model/package.scm +++ b/guix-data-service/model/package.scm @@ -39,21 +39,24 @@ branches-by-package-version)) (define (select-existing-package-entries package-entries) - (string-append "SELECT id, packages.name, packages.version, " - "packages.package_metadata_id " - "FROM packages " - "JOIN (VALUES " - (string-join (map (lambda (package-entry) - (apply - simple-format - #f "('~A', '~A', ~A)" - package-entry)) - package-entries) - ", ") - ") AS vals (name, version, package_metadata_id) " - "ON packages.name = vals.name AND " - "packages.version = vals.version AND " - "packages.package_metadata_id = vals.package_metadata_id")) + (string-append + " +SELECT id, packages.name, packages.version, + packages.package_metadata_id +FROM packages +JOIN (VALUES " + (string-join (map (lambda (package-entry) + (apply + simple-format + #f "('~A', '~A', ~A)" + package-entry)) + package-entries) + ", ") + " +) AS vals (name, version, package_metadata_id) + ON packages.name = vals.name + AND packages.version = vals.version + AND packages.package_metadata_id = vals.package_metadata_id")) (define* (select-packages-in-revision conn commit-hash #:key limit-results @@ -242,20 +245,21 @@ WHERE packages.id IN ( (exec-query conn query (list commit-hash))) (define (insert-into-package-entries package-entries) - (string-append "INSERT INTO packages " - "(name, version, package_metadata_id) VALUES " - (string-join - (map - (match-lambda - ((name version package_metadata_id) - (simple-format #f "('~A', '~A', ~A)" - name - version - package_metadata_id))) - package-entries) - ",") - " RETURNING id" - ";")) + (string-append + " +INSERT INTO packages (name, version, package_metadata_id) VALUES " + (string-join + (map + (match-lambda + ((name version package_metadata_id) + (simple-format #f "('~A', '~A', ~A)" + name + version + package_metadata_id))) + package-entries) + ",") + " +RETURNING id")) (define (inferior-packages->package-ids conn package-entries) (insert-missing-data-and-return-all-ids -- cgit v1.2.3