From e5ce6d6f23728bd3c5201fe6133ba75fcd3af4c9 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Mon, 20 Oct 2025 20:43:00 +0200 Subject: Realign create-* model accessors. Creating a model entity must return the newly created entity. --- models/nutrient.rkt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'models/nutrient.rkt') diff --git a/models/nutrient.rkt b/models/nutrient.rkt index f2ef4fd..6bbaf56 100644 --- a/models/nutrient.rkt +++ b/models/nutrient.rkt @@ -31,9 +31,13 @@ ;; CREATE (define (create-nutrient! name formula) - (query-exec (current-conn) - (insert #:into nutrients - #:set [canonical_name ,name] [formula ,formula]))) + (define existing-nutrient (get-nutrient #:name name #:formula formula)) + (define (new-nutrient) + (query-exec (current-conn) + (insert #:into nutrients + #:set [canonical_name ,name] [formula ,formula]))) + (or existing-nutrient + (new-nutrient))) ;; READ -- cgit v1.2.3