Source

SQLRat / src / test / clj / org / bituf / sqlrat / test / clause.clj

Diff from to

File src/test/clj/org/bituf/sqlrat/test/clause.clj

 (deftest test-op2-with-subquery
   (let [k :id
         ;; sub-query
-        qs "SELECT someid FROM sometable WHERE q=?" ;; query string
-        qp 10      ;; query parameter
-        q  [qs qp] ;; (sub)query
+        qs "SELECT someid FROM sometable WHERE q=?" ; query string
+        qp 10      ; query parameter
+        q  [qs qp] ; (sub)query
         v (as-clause q)
-        e (str "(" qs ")") ;; enclosed sub-query
+        e (str "(" qs ")") ; enclosed sub-query
         s=?  [(str "id="  e) qp]
         s<>? [(str "id<>" e) qp]
         s!=? [(str "id!=" e) qp]
             45 67 89 "Foo" "Bar" "Baz"]
           (AND
             (OR (>=? :id 45) (between? :cnt 67 89))
-            (in? :name ["Foo" "Bar" "Baz"]))))))
+            (in? :name ["Foo" "Bar" "Baz"])))))
+  (testing "Sample 2"
+    (is (= ["SELECT col1, col2, AVG(col3) AS calc3 FROM emp WHERE col5 IN (?, ?, ?, ?, ?) GROUP BY col2 ORDER BY col1 LIMIT ?, ?"
+            1 2 3 4 5 10 20]
+          (SELECT (>| :col1 :col2 (asfn :calc3 :AVG :col3))
+            (FROM :emp)
+            (WHERE (in? :col5 [1 2 3 4 5]))
+            (GROUPBY :col2)
+            (>> " ORDER BY" :col1)
+            (limit 10 20))))))
 
 
 (defn test-ns-hook []