diff options
| author | Marius Peter <dev@marius-peter.com> | 2025-10-20 20:41:07 +0200 |
|---|---|---|
| committer | Marius Peter <dev@marius-peter.com> | 2025-10-20 20:41:07 +0200 |
| commit | fddbcb3923d3dd019d07b3f37c033fab36c2cadc (patch) | |
| tree | 87a185fe72e0c57e663677a004d7d24ef31fa314 /models/fertilizer-product.rkt | |
| parent | 9620cae7bba35503a2ea4679938f76749a34245a (diff) | |
Simplify get-* model accessors.
Diffstat (limited to 'models/fertilizer-product.rkt')
| -rw-r--r-- | models/fertilizer-product.rkt | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/models/fertilizer-product.rkt b/models/fertilizer-product.rkt index 254ce35..073ef4f 100644 --- a/models/fertilizer-product.rkt +++ b/models/fertilizer-product.rkt @@ -13,12 +13,7 @@ number?))) (string?) fertilizer-product?)] - [get-fertilizer-products (->* () - (#:id - (or/c #f exact-nonnegative-integer?) - #:brand-name - (or/c #f string?)) - (listof fertilizer-product?))] + [get-fertilizer-products (-> (listof fertilizer-product?))] [get-fertilizer-product (->* () (#:id (or/c #f exact-nonnegative-integer?) @@ -85,23 +80,12 @@ ;; READ -(define (get-fertilizer-products #:id [id #f] - #:brand-name [brand-name #f]) - (define (where-expr) - (define clauses - (filter values - (list (and id (format "id = ~e" id)) - (and brand-name (format "brand_name = ~e" brand-name))))) - (cond - [(null? clauses) ""] - [else (format "WHERE ~a" (string-join clauses " AND "))])) - (define query (string-join - `("SELECT id, brand_name" - "FROM fertilizer_products" - ,(where-expr) - "ORDER BY id ASC"))) +(define (get-fertilizer-products) (for/list ([(id* brand-name*) - (in-query (current-conn) query)]) + (in-query (current-conn) + (select id brand_name + #:from fertilizer_products + #:order-by canonical_name #:asc))]) (fertilizer-product id* brand-name*))) (define (get-fertilizer-product #:id [id #f] |