diff options
author | Christopher Baines <mail@cbaines.net> | 2022-07-08 12:04:31 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2022-07-08 13:47:52 +0100 |
commit | db37d9f6a801a2ae41cd54dd1c8fad4866d4fdea (patch) | |
tree | 7319941b715a10c4dc8c70020c0c63d63524fc9b /guix-data-service/model | |
parent | 811256a92026f7ea25194c987e177482fd698f15 (diff) | |
download | data-service-db37d9f6a801a2ae41cd54dd1c8fad4866d4fdea.tar data-service-db37d9f6a801a2ae41cd54dd1c8fad4866d4fdea.tar.gz |
Split out inserting derivation output details sets
So that this can be used when inserting builds.
Diffstat (limited to 'guix-data-service/model')
-rw-r--r-- | guix-data-service/model/derivation.scm | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/guix-data-service/model/derivation.scm b/guix-data-service/model/derivation.scm index 17b1eee..696e2fd 100644 --- a/guix-data-service/model/derivation.scm +++ b/guix-data-service/model/derivation.scm @@ -54,6 +54,7 @@ select-derivation-outputs-in-revision fix-derivation-output-details-hash-encoding derivation-output-details->derivation-output-details-ids + derivation-output-details-ids->derivation-output-details-set-id select-derivations-by-revision-name-and-version select-derivation-inputs-by-derivation-id select-serialized-derivation-by-file-name @@ -985,26 +986,10 @@ LOCK TABLE ONLY derivation_output_details (assq-ref details 'recursive))) derivation-output-details))) -(define (insert-derivation-outputs conn - derivation-id - names-and-derivation-outputs) - (define (insert-into-derivation-outputs output-names - derivation-output-details-ids) - (string-append "INSERT INTO derivation_outputs " - "(derivation_id, name, derivation_output_details_id) VALUES " - (string-join - (map (lambda (output-name derivation-output-details-id) - (simple-format - #f "(~A, '~A', ~A)" - derivation-id - output-name - derivation-output-details-id)) - output-names - derivation-output-details-ids) - ",") - ";")) - - (define (select-derivation-output-details-sets-id derivation-output-details-ids) +(define (derivation-output-details-ids->derivation-output-details-set-id + conn + derivation-output-details-ids) + (define (select-derivation-output-details-sets-id) (match (exec-query conn (string-append @@ -1020,8 +1005,7 @@ WHERE derivation_output_details_ids = ARRAY[" (string->number id)) (_ #f))) - (define (insert-into-derivation-output-details-sets - derivation-output-details-ids) + (define (insert-into-derivation-output-details-sets) (match (exec-query conn (string-append @@ -1035,6 +1019,28 @@ RETURNING id")) (((id)) (string->number id)))) + (or (select-derivation-output-details-sets-id) + (insert-into-derivation-output-details-sets))) + +(define (insert-derivation-outputs conn + derivation-id + names-and-derivation-outputs) + (define (insert-into-derivation-outputs output-names + derivation-output-details-ids) + (string-append "INSERT INTO derivation_outputs " + "(derivation_id, name, derivation_output_details_id) VALUES " + (string-join + (map (lambda (output-name derivation-output-details-id) + (simple-format + #f "(~A, '~A', ~A)" + derivation-id + output-name + derivation-output-details-id)) + output-names + derivation-output-details-ids) + ",") + ";")) + (define (insert-into-derivations-by-output-details-set derivation_output_details_set_id) (exec-query @@ -1072,9 +1078,9 @@ VALUES ($1, $2)" derivation-output-details-ids)) (insert-into-derivations-by-output-details-set - (or - (select-derivation-output-details-sets-id derivation-output-details-ids) - (insert-into-derivation-output-details-sets derivation-output-details-ids))) + (derivation-output-details-ids->derivation-output-details-set-id + conn + derivation-output-details-ids)) derivation-output-details-ids)) |