(apply-criteria sql criteria)
(apply-criteria sql criteria options)
Adds a WHERE clause to a sql map based on the specified criteria.
The criteria can be a map, which will result in a set of conditions joined by AND.
(apply-criteria {:first-name "John" :last-name "Doe"}) => {:where [:and [:= :first_name "Jone"] [:= :last_name "Doe"]]}
Maps can be joined with OR logic also. [:or {:first-name "John"} {:last-name "Doe"}] => {:where [:or [:= :first_name "John"] [:= :last_name "Doe"]]}
Related tables can be included in a query by passing a :relationships map in the options and including a compound key in the criteria.
(apply-criteria {[:user :last-name] "Doe"} {:target :order :relationships {#{:user :order} {:primary-table :users :foreign-table :orders :foreign-id :user_id}}}) => {:where [:= :users.last_name "Doe"] :from :orders :join [:users [:= :users.id :orders.user_id]]} If a table name does not match the key used to identify the model type, it will first be looked up from the :table-names map in options. Otherwise, an attempt will be made to make it plural.
Adds a WHERE clause to a sql map based on the specified criteria. The criteria can be a map, which will result in a set of conditions joined by AND. (apply-criteria {:first-name "John" :last-name "Doe"}) => {:where [:and [:= :first_name "Jone"] [:= :last_name "Doe"]]} Maps can be joined with OR logic also. [:or {:first-name "John"} {:last-name "Doe"}] => {:where [:or [:= :first_name "John"] [:= :last_name "Doe"]]} Related tables can be included in a query by passing a :relationships map in the options and including a compound key in the criteria. (apply-criteria {[:user :last-name] "Doe"} {:target :order :relationships {#{:user :order} {:primary-table :users :foreign-table :orders :foreign-id :user_id}}}) => {:where [:= :users.last_name "Doe"] :from :orders :join [:users [:= :users.id :orders.user_id]]} If a table name does not match the key used to identify the model type, it will first be looked up from the :table-names map in options. Otherwise, an attempt will be made to make it plural.
(deep-contains? data k)
Returns a boolean value indicating whether or not a field is specified in a criteria structure.
(deep-contains? {:first-name "John"} :first-name) => true (deep-contains? {:last-name "Doe"} :first-name) => false (deep-contains? [:or {:first-name "John"} {:last-name "Doe"}] :first-name) => true
Returns a boolean value indicating whether or not a field is specified in a criteria structure. (deep-contains? {:first-name "John"} :first-name) => true (deep-contains? {:last-name "Doe"} :first-name) => false (deep-contains? [:or {:first-name "John"} {:last-name "Doe"}] :first-name) => true
Removes a value from a criteria structure.
(deep-dissoc [:or {:first-name "John"} {:last-name "Doe"}] :first-name) => {:last-name "Doe"}
Removes a value from a criteria structure. (deep-dissoc [:or {:first-name "John"} {:last-name "Doe"}] :first-name) => {:last-name "Doe"}
(deep-get data k)
Returns the value specified for a field within a criteria structure.
(deep-get {:first-name "John"} :first-name) => "John" (deep-get {:last-name "Doe"} :first-name) => nil (deep-get [:or {:first-name "John"} {:last-name "Doe"}] :first-name) => "John"
Returns the value specified for a field within a criteria structure. (deep-get {:first-name "John"} :first-name) => "John" (deep-get {:last-name "Doe"} :first-name) => nil (deep-get [:or {:first-name "John"} {:last-name "Doe"}] :first-name) => "John"
(ensure-join sql table criteria)
Ensures that the specified sql map contains the specified join clause
Ensures that the specified sql map contains the specified join clause
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close