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-measurement.rkt | |
| parent | 3008eb25f79ef1ed54fcc2b3f5b6635b34394680 (diff) | |
Simplify retrieval of all nutrient measurements and targets.
Diffstat (limited to 'models/nutrient-measurement.rkt')
| -rw-r--r-- | models/nutrient-measurement.rkt | 28 | 
1 files changed, 8 insertions, 20 deletions
diff --git a/models/nutrient-measurement.rkt b/models/nutrient-measurement.rkt index 8364aa7..28e3bdc 100644 --- a/models/nutrient-measurement.rkt +++ b/models/nutrient-measurement.rkt @@ -12,10 +12,8 @@                                               nutrient?                                               number?))                                      nutrient-measurement?)] -  [get-nutrient-measurements (->* () -                                  (#:id          (or/c #f exact-nonnegative-integer?) -                                   #:measured-on (or/c #f string?)) -                                  (listof nutrient-measurement?))] +  [get-nutrient-measurements (-> void? +                                 (listof nutrient-measurement?))]    [get-nutrient-measurement (->* ()                                   (#:id          (or/c #f exact-nonnegative-integer?)                                    #:measured-on (or/c #f string?)) @@ -80,23 +78,13 @@  ;; READ -(define (get-nutrient-measurements #:id [id #f] -                                   #:measured-on [measured-on #f]) -  (define (where-expr) -    (define clauses -      (filter values -              (list (and id (format "id = ~e" id)) -                    (and measured-on (format "measured_on = ~e" measured-on))))) -    (cond -      [(null? clauses) ""] -      [else (format "WHERE ~a" (string-join clauses " AND "))])) -  (define query (string-join -                 `("SELECT id, measured_on" -                   "FROM nutrient_measurements" -                   ,(where-expr) -                   "ORDER BY id ASC"))) +(define (get-nutrient-measurements)    (for/list ([(id* measured-on*) -              (in-query (current-conn) query)]) +              (in-query (current-conn) +                        (string-join +                         `("SELECT id, measured_on" +                           "FROM nutrient_measurements" +                           "ORDER BY id ASC")))])      (nutrient-measurement id* measured-on*)))  (define (get-nutrient-measurement #:id [id #f]  |