diff options
| author | Marius Peter <dev@marius-peter.com> | 2025-12-13 17:54:41 +0100 |
|---|---|---|
| committer | Marius Peter <dev@marius-peter.com> | 2025-12-13 17:54:41 +0100 |
| commit | 3b7f77480ab5b5fe1a14bfba7a6f1b486aaa9a0a (patch) | |
| tree | 25a0840e5e243bb09e2be7aad99b7971f8c795d7 /models/nutrient-value.rkt | |
| parent | 649d6fa5ad5883f62c4df200b7a9958bba12fe3d (diff) | |
Add fertilizer product updating logic.
Diffstat (limited to 'models/nutrient-value.rkt')
| -rw-r--r-- | models/nutrient-value.rkt | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/models/nutrient-value.rkt b/models/nutrient-value.rkt index b5798db..08bcfad 100644 --- a/models/nutrient-value.rkt +++ b/models/nutrient-value.rkt @@ -5,6 +5,7 @@ nutrient-value-hash/c (contract-out [insert-nutrient-values (-> connection? db-id? nutrient-value-hash/c (listof (cons/c symbol? any/c)))] + [update-nutrient-values! (-> connection? db-id? nutrient-value-hash/c void?)] [residuals->nutrient-value-hash (-> (listof residual-vector/c) nutrient-value-hash/c)])) @@ -33,6 +34,13 @@ #:from (TableExpr:AST ,(make-values*-table-expr-ast nv-rows))))) (simple-result-info result)) +(define (update-nutrient-values! conn nvs-id nutrient-values) + (for ([(n v) (in-hash nutrient-values)]) + (query-exec conn + (update nutrient_values + #:set [value_ppm ,v] + #:where (and (= value_set_id ,nvs-id) (= nutrient_id ,(nutrient-id n))))))) + (define (residuals->nutrient-value-hash residuals) (for/hash ([r (in-list residuals)]) (match-define (vector n-id n-canonical-name n-french-name n-formula value-ppm) r) |