From 4de1d445ec4b012ed8fcd3245af47ea5b6d32032 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Wed, 24 Jun 2020 22:25:28 -0700 Subject: [PATCH] Address #124 by fixing bug in builder; adding tests --- src/next/jdbc/sql/builder.clj | 2 +- test/next/jdbc/sql_test.clj | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/next/jdbc/sql/builder.clj b/src/next/jdbc/sql/builder.clj index a9ab068..53ae646 100644 --- a/src/next/jdbc/sql/builder.clj +++ b/src/next/jdbc/sql/builder.clj @@ -155,7 +155,7 @@ where-params (cond (map? where-params) (by-keys where-params :where opts) (= :all where-params) - [] + [nil] :else (into [(str "WHERE " (first where-params))] (rest where-params))) diff --git a/test/next/jdbc/sql_test.clj b/test/next/jdbc/sql_test.clj index c10473d..8993ebb 100644 --- a/test/next/jdbc/sql_test.clj +++ b/test/next/jdbc/sql_test.clj @@ -26,6 +26,19 @@ (is (= 1 ((column :FRUIT/ID) (first rs)))) (is (= 4 ((column :FRUIT/ID) (last rs)))))) +(deftest test-find-all-offset + (let [ds-opts (jdbc/with-options (ds) (default-options)) + rs (sql/find-by-keys ds-opts :fruit :all + (assoc (if (or (mysql?) (sqlite?)) + {:limit 2 :offset 1} + {:offset 1 :fetch 2}) + :order-by [:id]))] + (is (= 2 (count rs))) + (is (every? map? rs)) + (is (every? meta rs)) + (is (= 2 ((column :FRUIT/ID) (first rs)))) + (is (= 3 ((column :FRUIT/ID) (last rs)))))) + (deftest test-find-by-keys (let [ds-opts (jdbc/with-options (ds) (default-options))] (let [rs (sql/find-by-keys ds-opts :fruit {:appearance "neon-green"})]