aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-12-26 09:34:35 +0000
committerChristopher Baines <mail@cbaines.net>2019-12-26 09:34:35 +0000
commite3d8a2371672ca962a80aa9d78a44447b2b9174b (patch)
tree3bd9fce0aa9ef1f806f2df4bfb65fcc2158c1e66
parentb504094262b78db0e00418d0cd7a921c982f7f68 (diff)
downloaddata-service-e3d8a2371672ca962a80aa9d78a44447b2b9174b.tar
data-service-e3d8a2371672ca962a80aa9d78a44447b2b9174b.tar.gz
Add a function to fetch a derivation by file name hash
-rw-r--r--guix-data-service/model/derivation.scm23
1 files changed, 23 insertions, 0 deletions
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