From fddbcb3923d3dd019d07b3f37c033fab36c2cadc Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Mon, 20 Oct 2025 20:41:07 +0200 Subject: Simplify get-* model accessors. --- models/fertilizer-product.rkt | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'models/fertilizer-product.rkt') 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] -- cgit v1.2.3