From e3d8a2371672ca962a80aa9d78a44447b2b9174b Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 26 Dec 2019 09:34:35 +0000 Subject: Add a function to fetch a derivation by file name hash --- guix-data-service/model/derivation.scm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'guix-data-service/model') diff --git a/guix-data-service/model/derivation.scm b/guix-data-service/model/derivation.scm index efccd6c..5e46a6e 100644 --- a/guix-data-service/model/derivation.scm +++ b/guix-data-service/model/derivation.scm @@ -14,6 +14,7 @@ #:export (valid-systems count-derivations select-derivation-by-file-name + select-derivation-by-file-name-hash select-derivation-outputs-by-derivation-id select-derivation-sources-by-derivation-id select-derivation-source-file-by-store-path @@ -588,6 +589,28 @@ VALUES ($1, $2)" derivation-output-details-ids)) +(define (select-derivation-by-file-name-hash conn file-name-hash) + (define query + (string-append + "SELECT id, file_name, builder, args, to_json(env_vars), system " + "FROM derivations " + "WHERE substring(file_name from 12 for 32) = $1")) + + (match (exec-query conn query (list file-name-hash)) + (() + #f) + (((id file_name builder args env_vars system)) + (list (string->number id) + file_name + builder + (parse-postgresql-array-string args) + (map (match-lambda + (#(key value) + `((key . ,key) + (value . ,value)))) + (vector->list (json-string->scm env_vars))) + system)))) + (define (select-derivation-by-file-name conn file-name) (define query (string-append -- cgit v1.2.3