diff options
| author | Marius Peter <dev@marius-peter.com> | 2025-10-20 20:43:00 +0200 | 
|---|---|---|
| committer | Marius Peter <dev@marius-peter.com> | 2025-10-20 20:43:00 +0200 | 
| commit | e5ce6d6f23728bd3c5201fe6133ba75fcd3af4c9 (patch) | |
| tree | 21b8c7927ee45093eab307aec2173807895a2fcd /models/nutrient.rkt | |
| parent | fddbcb3923d3dd019d07b3f37c033fab36c2cadc (diff) | |
Realign create-* model accessors.
Creating a model entity must return the newly created entity.
Diffstat (limited to 'models/nutrient.rkt')
| -rw-r--r-- | models/nutrient.rkt | 10 | 
1 files changed, 7 insertions, 3 deletions
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  |