diff options
| author | Marius Peter <dev@marius-peter.com> | 2025-10-19 21:27:58 +0200 | 
|---|---|---|
| committer | Marius Peter <dev@marius-peter.com> | 2025-10-19 21:27:58 +0200 | 
| commit | 70ae2a00292e7e2cfc8530a3301e3f5b0654f5f2 (patch) | |
| tree | 18a3be31d49c68c391e0142181429ff149e91beb /models/nutrient-target.rkt | |
| parent | 3008eb25f79ef1ed54fcc2b3f5b6635b34394680 (diff) | |
Simplify retrieval of all nutrient measurements and targets.
Diffstat (limited to 'models/nutrient-target.rkt')
| -rw-r--r-- | models/nutrient-target.rkt | 30 | 
1 files changed, 8 insertions, 22 deletions
diff --git a/models/nutrient-target.rkt b/models/nutrient-target.rkt index 6483997..e9c168e 100644 --- a/models/nutrient-target.rkt +++ b/models/nutrient-target.rkt @@ -12,12 +12,8 @@                                          nutrient?                                          number?))                                 nutrient-target?)] -  [get-nutrient-targets (->* () -                             (#:id -                              (or/c #f exact-nonnegative-integer?) -                              #:effective-on -                              (or/c #f string?)) -                             (listof nutrient-target?))] +  [get-nutrient-targets (-> void? +                            (listof nutrient-target?))]    [get-nutrient-target (->* ()                              (#:id                               (or/c #f exact-nonnegative-integer?) @@ -85,23 +81,13 @@  ;; READ -(define (get-nutrient-targets #:id [id #f] -                                   #:effective-on [effective-on #f]) -  (define (where-expr) -    (define clauses -      (filter values -              (list (and id (format "id = ~e" id)) -                    (and effective-on (format "effective_on = ~e" effective-on))))) -    (cond -      [(null? clauses) ""] -      [else (format "WHERE ~a" (string-join clauses " AND "))])) -  (define query (string-join -                 `("SELECT id, effective_on" -                   "FROM nutrient_targets" -                   ,(where-expr) -                   "ORDER BY id ASC"))) +(define (get-nutrient-targets)    (for/list ([(id* effective-on*) -              (in-query (current-conn) query)]) +              (in-query (current-conn) +                        (string-join +                         `("SELECT id, effective_on" +                           "FROM nutrient_targets" +                           "ORDER BY id ASC")))])      (nutrient-target id* effective-on*)))  (define (get-nutrient-target #:id [id #f]  |