Skip to content
/ qb Public

Minimalistic data-oriented toolbox for building conditional Datalog queries

License

Notifications You must be signed in to change notification settings

fmnoise/qb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Minimalistic data-oriented toolbox for building conditional Datalog queries

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published