qualify, docs
This commit is contained in:
parent
92feca7eec
commit
cb99df7c36
1 changed files with 31 additions and 2 deletions
|
|
@ -3,14 +3,43 @@
|
|||
(:require [honeysql.format :as format]
|
||||
[honeysql.types :as types]
|
||||
[honeysql.helpers :refer [build-clause]]
|
||||
[honeysql.util :refer [defalias]]))
|
||||
[honeysql.util :refer [defalias]]
|
||||
[clojure.string :as string]))
|
||||
|
||||
(defalias call types/call)
|
||||
(defalias raw types/raw)
|
||||
(defalias format format/format)
|
||||
(defalias format-predicate format/format-predicate)
|
||||
|
||||
(defn build [& clauses]
|
||||
(defn qualify
|
||||
"Takes one or more keyword or string qualifers and name. Returns
|
||||
a keyword of the concatenated qualifiers and name separated by periods.
|
||||
|
||||
(qualify :foo \"bar\" :baz) => :foo.bar.baz"
|
||||
[& qualifiers+name]
|
||||
(keyword
|
||||
(string/join "." (map #(if (keyword? %) (name %) (str %))
|
||||
(remove nil? qualifiers+name)))))
|
||||
|
||||
(defn build
|
||||
"Takes a series of clause+data pairs and returns a SQL map. Example:
|
||||
|
||||
(build :select [:a :b]
|
||||
:from :bar)
|
||||
|
||||
Clauses are defined with the honeysql.helpers/build-clause multimethod.
|
||||
Built-in clauses include:
|
||||
|
||||
:select, :merge-select, :un-select
|
||||
:from, :merge-from
|
||||
:join, :merge-join
|
||||
:where, :merge-where
|
||||
:group-by, :merge-group-by
|
||||
:having, :merge-having
|
||||
:limit
|
||||
:offset
|
||||
:modifiers, :merge-modifiers"
|
||||
[& clauses]
|
||||
(let [[base clauses] (if (map? (first clauses))
|
||||
[(first clauses) (rest clauses)]
|
||||
[{} clauses])]
|
||||
|
|
|
|||
Loading…
Reference in a new issue