This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-18
Channels
- # announcements (2)
- # babashka (35)
- # beginners (59)
- # calva (17)
- # cider (3)
- # clerk (7)
- # clj-kondo (21)
- # cljfx (9)
- # cljs-dev (76)
- # clojure (98)
- # clojure-austin (3)
- # clojure-brasil (1)
- # clojure-europe (11)
- # clojure-gamedev (4)
- # clojurescript (14)
- # consulting (7)
- # cursive (6)
- # datascript (4)
- # datomic (12)
- # emacs (18)
- # events (2)
- # graalvm (9)
- # humbleui (3)
- # hyperfiddle (18)
- # jobs (4)
- # missionary (12)
- # nextjournal (2)
- # nrepl (7)
- # off-topic (31)
- # practicalli (2)
- # rdf (6)
- # releases (2)
- # scittle (10)
- # xtdb (9)
(I am new in Clojure and Datomic) Hello everyone, In this function my transact functionalities are not working. (ı just separated codes in another namespace to make my code more readable and clean then after that I started facing that problem). When I run transact functions manually in other namespaces where my db stands then everything works fine. I think my sell-all-items-in-cart function is wrong or maybe "for" is wrong. Can anyone take a look, please? Thanks for separeting time.
I guess my text snippet does not show the code. So let me copy it here.
(identity @!my-cart)
;=> [["bariscan" "mammut" 3] ["bariscan" "lacoste" 7] ["bariscan" "mammut" 1] ["bariscan" "canada goose" 3]]
(for [[username label order-size] @!my-cart]
(pr username label order-size)
)
;"bariscan" "mammut" 3"bariscan" "lacoste" 7"bariscan" "mammut" 1"bariscan" "canada goose" 3=> (nil nil nil nil)
(defn sell-all-items-in-cart [db conn]
(def db (d/db conn)) ;;refresh database
(for [[username label order-size] @!my-cart]
(if (>= (stock-check-by-label db label) order-size)
(if (user-validation-check-by-id db (get-user-id-by-username db username))
((d/transact conn {:tx-data [{:stock/product (get-entity-id-by-label db label)
:stock/amount (- (stock-check-by-label db label) order-size)}]})
(d/transact conn {:tx-data [{:order/product (get-entity-id-by-label db label)
:order/user (get-user-entity-id-by-userid db (get-user-id-by-username db username))
:order/size order-size}]}))
(print "UNKNOWN USER!!")
)
(print "OUT OF STOCK!!
Stock size is: " (stock-check-by-label db label))
)
)
(swap! !my-cart remove-all-elements-in-cart)
(def db (d/db conn)) ;;refresh database
)
for
is lazy, so any side effecting functions (like d/transact
) won’t run until you realise the sequence for produces. you can use doseq
in this instance, or wrap your for
in doall
(doall
(for [... ...]))
you also have an additional parenthesis wrapping your first d/transact
call which will break when the seq is realised 🙂Hello, thank you for your answer. I going to work on your advice. Secondary, which parenthesis is wrong still cant find it. I used "if" check, so that's why I added one more parenthesis to "true block".
(if (user-validation-check-by-id db (get-user-id-by-username db username))
(;true block
(d/transact conn {:tx-data [{:stock/product (get-entity-id-by-label db label)
:stock/amount (- (stock-check-by-label db label) order-size)}]})
(d/transact conn {:tx-data [{:order/product (get-entity-id-by-label db label)
:order/user (get-user-entity-id-by-userid db (get-user-id-by-username db username))
:order/size order-size}]}))
(;false block
print "UNKNOWN USER!!")
)
ah yeah, what you need to use there is (do (d/transact …) …)
, instead of the additional parenthesis around (; true block …)
Are there any plans to move ions deps to maven? For some reason I assumed opening up datomic-cloud would include ions but that doesn't seem to be the case as I don't see them there yet.
Datomic Cloud is still being Freed. We're moving in that direction, but have some decisions and work to do
Howdy friends! https://forum.datomic.com/t/datomic-1-0-6733-pro-now-available/2227
