diff options
Diffstat (limited to 'models/nutrient.rkt')
| -rw-r--r-- | models/nutrient.rkt | 28 | 
1 files changed, 5 insertions, 23 deletions
diff --git a/models/nutrient.rkt b/models/nutrient.rkt index 5a32e70..f2ef4fd 100644 --- a/models/nutrient.rkt +++ b/models/nutrient.rkt @@ -8,11 +8,7 @@   ;; SQL CRUD   (contract-out    [create-nutrient! (-> string? string? void?)] -  [get-nutrients (->* () -                      (#:id      (or/c #f exact-nonnegative-integer?) -                       #:name    (or/c #f string?) -                       #:formula (or/c #f string?)) -                      (listof nutrient?))] +  [get-nutrients (-> (listof nutrient?))]    [get-nutrient (->* ()                       (#:id      (or/c #f exact-nonnegative-integer?)                        #:name    (or/c #f string?) @@ -42,26 +38,12 @@  ;; READ -(define (get-nutrients #:id [id #f] -                       #:name [name #f] -                       #:formula [formula #f]) -  (define (where-expr) -    (define clauses -      (filter values -              (list -               (and id (format "id = ~e" id)) -               (and name (format "canonical_name = ~e" name)) -               (and formula (format "formula = ~e" formula))))) -    (cond -      [(null? clauses) ""] -      [else (format "WHERE ~a" (string-join clauses " AND "))])) +(define (get-nutrients)    (for/list ([(id* name* formula*)                (in-query (current-conn) -                        (string-join -                         `("SELECT id, canonical_name, formula" -                           "FROM nutrients" -                           ,(where-expr) -                           "ORDER BY id ASC")))]) +                        (select id canonical_name formula +                                #:from nutrients +                                #:order-by id #:asc))])      (nutrient id* name* formula*)))  (define (get-nutrient #:id [id #f]  |