Made HoneySQL helpers compatible with ClojureScript
This commit is contained in:
parent
93e66c90c4
commit
b8aaac02aa
1 changed files with 15 additions and 13 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
(ns honeysql.helpers
|
(ns honeysql.helpers
|
||||||
|
#?(:cljs (:require-macros [honeysql.helpers :refer [defhelper]]))
|
||||||
(:refer-clojure :exclude [update]))
|
(:refer-clojure :exclude [update]))
|
||||||
|
|
||||||
(defmulti build-clause (fn [name & args]
|
(defmulti build-clause (fn [name & args]
|
||||||
|
|
@ -7,18 +8,19 @@
|
||||||
(defmethod build-clause :default [_ m & args]
|
(defmethod build-clause :default [_ m & args]
|
||||||
m)
|
m)
|
||||||
|
|
||||||
(defmacro defhelper [helper arglist & more]
|
#?(:clj
|
||||||
(let [kw (keyword (name helper))]
|
(defmacro defhelper [helper arglist & more]
|
||||||
`(do
|
(let [kw (keyword (name helper))]
|
||||||
(defmethod build-clause ~kw ~(into ['_] arglist) ~@more)
|
`(do
|
||||||
(doto (defn ~helper [& args#]
|
(defmethod build-clause ~kw ~(into ['_] arglist) ~@more)
|
||||||
(let [[m# args#] (if (map? (first args#))
|
(doto (defn ~helper [& args#]
|
||||||
[(first args#) (rest args#)]
|
(let [[m# args#] (if (map? (first args#))
|
||||||
[{} args#])]
|
[(first args#) (rest args#)]
|
||||||
(build-clause ~kw m# args#)))
|
[{} args#])]
|
||||||
;; maintain the original arglist instead of getting
|
(build-clause ~kw m# args#)))
|
||||||
;; ([& args__6880__auto__])
|
;; maintain the original arglist instead of getting
|
||||||
(alter-meta! assoc :arglists '(~arglist))))))
|
;; ([& args__6880__auto__])
|
||||||
|
(alter-meta! assoc :arglists '(~arglist)))))))
|
||||||
|
|
||||||
(defn collify [x]
|
(defn collify [x]
|
||||||
(if (coll? x) x [x]))
|
(if (coll? x) x [x]))
|
||||||
|
|
@ -224,7 +226,7 @@
|
||||||
(defn delete-from
|
(defn delete-from
|
||||||
([table] (delete-from nil table))
|
([table] (delete-from nil table))
|
||||||
([m table] (build-clause :delete-from m table)))
|
([m table] (build-clause :delete-from m table)))
|
||||||
|
|
||||||
(defmethod build-clause :with [_ m ctes]
|
(defmethod build-clause :with [_ m ctes]
|
||||||
(assoc m :with ctes))
|
(assoc m :with ctes))
|
||||||
|
|
||||||
Loading…
Reference in a new issue