diff --git a/src/suricatta/dsl.clj b/src/suricatta/dsl.clj index 6166f0a..4c352a3 100644 --- a/src/suricatta/dsl.clj +++ b/src/suricatta/dsl.clj @@ -486,6 +486,12 @@ (defer (DSL/exists @q))) +(defn not-exists + "Create a not-exists condition." + [q] + (defer + (DSL/notExists @q))) + (defn group-by [q & fields] (defer 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"