allow custom clauses
This commit is contained in:
parent
faa495c362
commit
e45a58f267
1 changed files with 8 additions and 1 deletions
|
|
@ -116,6 +116,8 @@
|
||||||
"Determines the order that clauses will be placed within generated SQL"
|
"Determines the order that clauses will be placed within generated SQL"
|
||||||
[:select :from :join :where :group-by :having :order-by :limit :offset])
|
[:select :from :join :where :group-by :having :order-by :limit :offset])
|
||||||
|
|
||||||
|
(def known-clauses (set clause-order))
|
||||||
|
|
||||||
(defn format [sql-map]
|
(defn format [sql-map]
|
||||||
(binding [*params* (atom [])]
|
(binding [*params* (atom [])]
|
||||||
(let [sql-str (to-sql sql-map)]
|
(let [sql-str (to-sql sql-map)]
|
||||||
|
|
@ -162,7 +164,9 @@
|
||||||
SqlRaw
|
SqlRaw
|
||||||
(-to-sql [x] (.s x))
|
(-to-sql [x] (.s x))
|
||||||
clojure.lang.IPersistentMap
|
clojure.lang.IPersistentMap
|
||||||
(-to-sql [x] (let [clause-ops (filter #(contains? x %) clause-order)
|
(-to-sql [x] (let [clause-ops (concat
|
||||||
|
(filter #(contains? x %) clause-order)
|
||||||
|
(remove known-clauses (keys x)))
|
||||||
sql-str (binding [*subquery?* true]
|
sql-str (binding [*subquery?* true]
|
||||||
(space-join
|
(space-join
|
||||||
(map (comp #(format-clause % x) #(find x %))
|
(map (comp #(format-clause % x) #(find x %))
|
||||||
|
|
@ -202,6 +206,9 @@
|
||||||
"Takes a map entry representing a clause and returns an SQL string"
|
"Takes a map entry representing a clause and returns an SQL string"
|
||||||
(fn [clause _] (key clause)))
|
(fn [clause _] (key clause)))
|
||||||
|
|
||||||
|
(defmethod format-clause :default [& _]
|
||||||
|
"")
|
||||||
|
|
||||||
(defmethod format-clause :select [[_ fields] sql-map]
|
(defmethod format-clause :select [[_ fields] sql-map]
|
||||||
(str "SELECT "
|
(str "SELECT "
|
||||||
(when (:modifiers sql-map)
|
(when (:modifiers sql-map)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue