Anonymous avatar Anonymous committed 8cdcf8a

move vars-with-earmuffs to util.clj

Comments (0)

Files changed (4)


 (defn ?
-  "Smart value-parameter function."
+  "Smart value-parameter function. If you pass a map, a key=value pattern is
+  applied. For other collections a parameterized value clause is generated. 
+  Arguments:
+    coll  (Collection) of data. If it is a map then equivalent to (? in=? coll)
+          else generates a parameterized SQL value clause
+    op2fn (Function) accepts two arguments, returns parameterized SQL clause
+    m     (Map) map of colnames versus values
+  Example:
+    user=> (? [1 2 3])
+    [\"?, ?, ?\" 1 2 3]
+    user=> (? #{10 nil 55})
+    [\"?, ?, ?\" nil 10 55]
+    user=> (? 34)
+    [\"?\" 34]
+    user=> (? {:a 10 :b \"hello\" :c [10 20 30] :d nil})
+    ([\"a=?\" 10] [\"b=?\" \"hello\"]
+     [\"c IN (?, ?, ?)\" 10 20 30] [\"d IS NULL\"])
+  See also:
+    as-value-clause, map-to-clauses"
   ([^IPersistentCollection coll]
+    (assert (coll? coll))
     (if (map? coll) (? in=? coll)
       (as-value-clause coll)))
   ([^IFn op2fn ^IPersistentMap m]
+    (assert (fn? op2fn))
+    (assert (map? m))
     (map-to-clauses op2fn m)))


   (:import [clojure.lang IFn Keyword IPersistentMap IPersistentVector]))
-(def *show-sql* true)
-(def *show-sql-results* false)
-(def *assert-args* true)
 ; ===== Utility functions and macros =====
 (defn- as-vector*


   (:import [clojure.lang IFn Keyword IPersistentMap IPersistentVector]))
+(def *show-sql* true)
+(def *show-sql-results* false)
+(def *assert-args* true)
 (defn bad-arg#
   "Throw IllegalArgumentException with specified arguments. Use this when you
    encounter bad/invalid parameters."


   (:use clojure.test))
-(binding [org.bituf.sqlrat.entity/*show-sql* true
-          org.bituf.sqlrat.entity/*show-sql-results* true
+(binding [org.bituf.sqlrat.util/*show-sql* true
+          org.bituf.sqlrat.util/*show-sql-results* true
           org.bituf.sqlrat.clause/*debug* false]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.