From f6a274362a5428667d8d6925a18371ef9a9bee4b Mon Sep 17 00:00:00 2001 From: Leon Mergen Date: Thu, 9 Jun 2016 15:28:19 +0200 Subject: [PATCH 1/3] Implements opposite of dsl/exists --- src/suricatta/dsl.clj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/suricatta/dsl.clj b/src/suricatta/dsl.clj index 6166f0a..654fea5 100644 --- a/src/suricatta/dsl.clj +++ b/src/suricatta/dsl.clj @@ -486,6 +486,12 @@ (defer (DSL/exists @q))) +(defn not-exists + "Create an exists condition." + [q] + (defer + (DSL/notExists @q))) + (defn group-by [q & fields] (defer From 9783e4a1e6b27e0295e047983b5ab65218dd28b6 Mon Sep 17 00:00:00 2001 From: Leon Mergen Date: Thu, 9 Jun 2016 15:29:18 +0200 Subject: [PATCH 2/3] Fixes documentation --- src/suricatta/dsl.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/suricatta/dsl.clj b/src/suricatta/dsl.clj index 654fea5..4c352a3 100644 --- a/src/suricatta/dsl.clj +++ b/src/suricatta/dsl.clj @@ -487,7 +487,7 @@ (DSL/exists @q))) (defn not-exists - "Create an exists condition." + "Create a not-exists condition." [q] (defer (DSL/notExists @q))) From 173e0a8ab0d266f6efdc36aba47363aa9aecb3ef Mon Sep 17 00:00:00 2001 From: Leon Mergen Date: Thu, 9 Jun 2016 15:30:21 +0200 Subject: [PATCH 3/3] Adds test case for not-exists --- test/suricatta/dsl_test.clj | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/suricatta/dsl_test.clj b/test/suricatta/dsl_test.clj index 485baaa..a4a459a 100644 --- a/test/suricatta/dsl_test.clj +++ b/test/suricatta/dsl_test.clj @@ -271,7 +271,15 @@ (dsl/where ["table.author_id = author.id"])))))] (is (= (fmt/sql q) "select fullname from author where exists (select id from table where (table.author_id = author.id))")))) -) + + (testing "Nested select in where clause using not-exists" + (let [q (-> (dsl/select :fullname) + (dsl/from :author) + (dsl/where (dsl/not-exists (-> (dsl/select :id) + (dsl/from :table) + (dsl/where ["table.author_id = author.id"])))))] + (is (= (fmt/sql q) + "select fullname from author where not exists (select id from table where (table.author_id = author.id))"))))) (deftest dsl-insert (testing "Insert statement from values as maps"