(add-input q binding source & [expand-coll?])
Adds query input. Last optional agrument turns automatic expanding of collection source into collection binding
Adds query input. Last optional agrument turns automatic expanding of collection source into collection binding
(data->query conditions)
(data->query src conditions)
Transforms map or vector into query map. Additional query options can be supplied with meta attached to conditions
:
:in
for source binding (defaults to $)
:find
for defining result binding (defaults to ?e)
:from
for defining entity binding (defaults to ?e)
:as
for defining query keys
:first
which will return scalar value
:nil
which indicates how to handle nils, defaults to :missing
, possible options are:
:missing
- replace nil values with [(missing? ...)]
:not
- replace nil values with [(not [...])]
:skip
- skip nil values
:aggregate
which can contain either a keyword or collection of function symbol and keyword in any order like [:order/total 'sum] or ['sum :order/total]
when aggregation is used, :with
instruction is automatically added
(data->query {:user/id 1 :user/type :admin}) ;; => {:query {:find [[?e ...]], :where [[?e :user/id ?user-id] [?e :user/type ?user-type]], :in [?user-id ?user-type]}, :args [1 :admin]}
(datq->query ^{:find '?user} {:user/id 1}) ;; => {:query {:find [[?user ...]], :where [[?user :user/id ?user-id]], :in [?user-id]}, :args [1]}
(data->query ^{:find '?user :as :user} {:user/id 1}) ;; => {:query {:find [?user], :keys [:user], :where [[?user :user/id ?user-id]], :in [?user-id]}, :args [1]}
(data->query ^{:aggregate ['sum :order/total]} {:order/id '_}) ;; => {:query {:find [(sum ?order-total) .], :where [[?e :order/id] [?e :order/total ?order-total]]}}
(data->query ^{:aggregate :order/customer} {:order/id '_}) ;; => {:query {:find [[?order-customer ...]], :where [[?e :order/id] [?e :order/customer ?order-customer]]}}
(data->query [:user/id 1 :user/type :admin]) ;; => {:query {:find [[?e ...]], :where [[?e :user/id ?user-id] [?e :user/type ?user-type]], :in [?user-id ?user-type]}, :args [1 :admin]}
(data->query ^{:find '?user} [:user/id 1]) ;; => {:query {:find [[?user ...]], :where [[?user :user/id ?user-id]], :in [?user-id]}, :args [1]}
(data->query ^{:find '?user :as :user} [:user/id 1]) ;; => {:query {:find [?user], :keys [:user], :where [[?user :user/id ?user-id]], :in [?user-id]}, :args [1]}
(data->query ^{:aggregate ['sum :order/total]} [:order/id '_]) ;; => {:query {:find [(sum ?order-total) .], :where [[?e :order/id] [?e :order/total ?order-total]]}}
(data->query ^{:aggregate :order/customer} [:order/id '_]) ;; => {:query {:find [[?order-customer ...]], :where [[?e :order/id] [?e :order/customer ?order-customer]]}}
Transforms map or vector into query map. Additional query options can be supplied with meta attached to `conditions`: `:in` for source binding (defaults to $) `:find` for defining result binding (defaults to ?e) `:from` for defining entity binding (defaults to ?e) `:as` for defining query keys `:first` which will return scalar value `:nil` which indicates how to handle nils, defaults to `:missing`, possible options are: `:missing` - replace nil values with [(missing? ...)] `:not` - replace nil values with [(not [...])] `:skip` - skip nil values `:aggregate` which can contain either a keyword or collection of function symbol and keyword in any order like [:order/total 'sum] or ['sum :order/total] when aggregation is used, `:with` instruction is automatically added (data->query {:user/id 1 :user/type :admin}) ;; => {:query {:find [[?e ...]], :where [[?e :user/id ?user-id] [?e :user/type ?user-type]], :in [?user-id ?user-type]}, :args [1 :admin]} (datq->query ^{:find '?user} {:user/id 1}) ;; => {:query {:find [[?user ...]], :where [[?user :user/id ?user-id]], :in [?user-id]}, :args [1]} (data->query ^{:find '?user :as :user} {:user/id 1}) ;; => {:query {:find [?user], :keys [:user], :where [[?user :user/id ?user-id]], :in [?user-id]}, :args [1]} (data->query ^{:aggregate ['sum :order/total]} {:order/id '_}) ;; => {:query {:find [(sum ?order-total) .], :where [[?e :order/id] [?e :order/total ?order-total]]}} (data->query ^{:aggregate :order/customer} {:order/id '_}) ;; => {:query {:find [[?order-customer ...]], :where [[?e :order/id] [?e :order/customer ?order-customer]]}} (data->query [:user/id 1 :user/type :admin]) ;; => {:query {:find [[?e ...]], :where [[?e :user/id ?user-id] [?e :user/type ?user-type]], :in [?user-id ?user-type]}, :args [1 :admin]} (data->query ^{:find '?user} [:user/id 1]) ;; => {:query {:find [[?user ...]], :where [[?user :user/id ?user-id]], :in [?user-id]}, :args [1]} (data->query ^{:find '?user :as :user} [:user/id 1]) ;; => {:query {:find [?user], :keys [:user], :where [[?user :user/id ?user-id]], :in [?user-id]}, :args [1]} (data->query ^{:aggregate ['sum :order/total]} [:order/id '_]) ;; => {:query {:find [(sum ?order-total) .], :where [[?e :order/id] [?e :order/total ?order-total]]}} (data->query ^{:aggregate :order/customer} [:order/id '_]) ;; => {:query {:find [[?order-customer ...]], :where [[?e :order/id] [?e :order/customer ?order-customer]]}}
(find bindings)
(find q bindings & [override?])
Adds bindings to query :find
Adds bindings to query `:find`
(find-coll binding)
(find-coll q binding)
Adds collection binding to query :find
Adds collection binding to query `:find`
(find-scalar binding)
(find-scalar q binding)
Adds scalar binding to query :find
Adds scalar binding to query `:find`
(in q src)
(in q binding source & inputs)
Adds query input. If binding for input is not specified, its added as $
as first argument.
If source is set?
, the corresponding collection binding is added
Adds query input. If binding for input is not specified, its added as `$` as first argument. If source is `set?`, the corresponding collection binding is added
(where q condition)
(where q condition input)
Adds condition to query. Accepts optional input
If input is nil, condition is transformed into (not [...]).
If input is set?
, the corresponding collection binding is addded
Adds condition to query. Accepts optional input If input is nil, condition is transformed into (not [...]). If input is `set?`, the corresponding collection binding is addded
(where* q conditions)
Adds multiple conditions/values from supplied collection to query using where
.
If condition needs to have supplied value, it should be wrapped in vector eg
(where* q
[[?e :order/id]
[['?e :order/customer '?c] customer]
Adds multiple conditions/values from supplied collection to query using `where`. If condition needs to have supplied value, it should be wrapped in vector eg (where* q [[?e :order/id] [['?e :order/customer '?c] customer]
(where-> q & conditions)
Adds multiple conditions/values to query using where
.
If condition needs to have supplied value, it should be wrapped in vector eg
(where-> q
['?e :order/id]
[['?e :order/customer '?c] customer]
Adds multiple conditions/values to query using `where`. If condition needs to have supplied value, it should be wrapped in vector eg (where-> q ['?e :order/id] [['?e :order/customer '?c] customer]
(where-missing q condition)
Adds missing?
condition to query. Condition may have or may not have source binding, $ is used then
Adds `missing?` condition to query. Condition may have or may not have source binding, $ is used then
(where-not q condition)
(where-not q condition input)
Adds not
condition to query. Accepts optional value.
If value is set, it's used as function to filter out conditions
Adds `not` condition to query. Accepts optional value. If value is set, it's used as function to filter out conditions
(where-not* q conditions)
Adds multiple conditions/values from supplied collection to query using where-not
.
If condition needs to have supplied value, it should be wrapped in vector eg
(where-not* q
[[?e :order/cancelled]
['?e :order/status '?s] status])
Adds multiple conditions/values from supplied collection to query using `where-not`. If condition needs to have supplied value, it should be wrapped in vector eg (where-not* q [[?e :order/cancelled] ['?e :order/status '?s] status])
(where? q cond-vals)
(where? q condition input)
Adds condition to query only if supplied input is not nil. Accepts either query condition and value or map/list/vector of conditions and values eg: (where? q {'[?e :order/id ?id] id '[?e :order/customer ?c] customer} (where? q ['[?e :order/id ?id] id '[?e :order/customer ?c] customer]
Adds condition to query only if supplied input is not nil. Accepts either query condition and value or map/list/vector of conditions and values eg: (where? q {'[?e :order/id ?id] id '[?e :order/customer ?c] customer} (where? q ['[?e :order/id ?id] id '[?e :order/customer ?c] customer]
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close