diff options
author | Christopher Baines <mail@cbaines.net> | 2021-04-24 05:58:48 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2021-04-24 06:00:47 +0100 |
commit | e38bddcae542bad878a4e9169fcf40fec72a1134 (patch) | |
tree | 42448cef6a4512ca47d886f3bf3f3c4de036f3c5 | |
parent | 1f078e1af0e3e08e3fef52dec9897977b6416a28 (diff) | |
download | data-service-e38bddcae542bad878a4e9169fcf40fec72a1134.tar data-service-e38bddcae542bad878a4e9169fcf40fec72a1134.tar.gz |
Reformat a couple of package related queries
-rw-r--r-- | guix-data-service/model/package.scm | 62 |
1 files 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 |