Skip to content

Commit

Permalink
Merge pull request #16 from solatis/master
Browse files Browse the repository at this point in the history
Implements dsl/not-exists
  • Loading branch information
niwinz authored Jun 11, 2016
2 parents 2ac344a + 173e0a8 commit d82b8eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/suricatta/dsl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion test/suricatta/dsl_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d82b8eb

Please sign in to comment.