Liking cljdoc? Tell your friends :D

Stand With Ukraine

qb Clojars Project

Minimalistic data-oriented toolbox for building conditional Datalog queries

Usage

(require '[fmnoise.qb :refer :all])

(defn orders-total-query [{:keys [customer-id order-id]}]
  (-> (find '[?c ?o (sum ?a)])
      (where? '[?o :order/id ?id] order-id)
      (where* '[[?o :order/customer ?c]
                [?o :order/items ?i]
                [?i :item/amount ?a]])
      (where? '[?c :customer/id ?cid] customer-id)
      (where-not '[?o :order/status :cancelled])))

(orders-total-query nil)
;; {:query {:find [?c ?o (sum ?a)]
;;          :where [[?o :order/customer ?c]
;;                  [?o :order/items ?i]
;;                  [?i :item/amount ?a]
;;                  (not [?o :order/status :cancelled])]}}

(orders-total-query {:customer-id 100})
;; {:query {:find [?c ?o (sum ?a)],
;;          :where [[?o :order/customer ?c]
;;                  [?o :order/items ?i]
;;                  [?i :item/amount ?a]
;;                  [?c :customer/id ?cid]
;;                  (not [?o :order/status :cancelled])]
;;          :in [?cid]}
;;  :args [100]}

(orders-total-query {:order-id 100})

;; {:query {:find [?c ?o (sum ?a)],
;;          :where [[?o :order/id ?id]
;;                  [?o :order/customer ?c]
;;                  [?o :order/items ?i]
;;                  [?i :item/amount ?a]
;;                  (not [?o :order/status :cancelled])],
;;          :in [?id]},
;;  :args [100]}

(orders-total-query {:order-id 100 :customer-id 100})
;; {:query {:find [?c ?o (sum ?a)],
;;          :where [[?o :order/id ?id]
;;                  [?o :order/customer ?c]
;;                  [?o :order/items ?i]
;;                  [?i :item/amount ?a]
;;                  [?c :customer/id ?cid]
;;                  (not [?o :order/status :cancelled])],
;;          :in [?id ?cid]},
;;  :args [100 100]}

License

Copyright fmnoise © 2023

Can you improve this documentation? These fine people already did:
ålex & fmnoise
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close