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/crop-requirement.rkt | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'models/crop-requirement.rkt') diff --git a/models/crop-requirement.rkt b/models/crop-requirement.rkt index f213441..d1c6ddd 100644 --- a/models/crop-requirement.rkt +++ b/models/crop-requirement.rkt @@ -13,12 +13,7 @@ number?))) ((or/c #f crop?)) crop-requirement?)] - [get-crop-requirements (->* () - (#:id - (or/c #f exact-nonnegative-integer?) - #:profile - (or/c #f string?)) - (listof crop-requirement?))] + [get-crop-requirements (-> (listof crop-requirement?))] [get-crop-requirement (->* () (#:id (or/c #f exact-nonnegative-integer?) @@ -90,27 +85,16 @@ ;; READ -(define (get-crop-requirements #:id [id #f] - #:profile [profile #f]) - (define (where-expr) - (define clauses - (filter values - (list (and id (format "id = ~e" id)) - (and profile (format "profile = ~e" profile))))) - (cond - [(null? clauses) ""] - [else (format "WHERE ~a" (string-join clauses " AND "))])) - (define query (string-join - `("SELECT id, profile" - "FROM crop_requirements" - ,(where-expr) - "ORDER BY id ASC"))) +(define (get-crop-requirements) (for/list ([(id* profile*) - (in-query (current-conn) query)]) + (in-query (current-conn) + (select id profile + #:from crop_requirements + #:order-by id #:asc))]) (crop-requirement id* profile*))) (define (get-crop-requirement #:id [id #f] - #:profile [profile #f]) + #:profile [profile #f]) (define (where-expr) (define clauses (filter values -- cgit v1.2.3