Skip to content

Commit

Permalink
Merge pull request korma#43 from leadtune/master
Browse files Browse the repository at this point in the history
Add a not-in predicate function
  • Loading branch information
ibdknox committed Mar 19, 2012
2 parents 1d11172 + 9c604b8 commit 4a55854
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/korma/sql/engine.clj
Expand Up @@ -161,6 +161,7 @@
'or 'korma.sql.fns/pred-or
'not 'korma.sql.fns/pred-not
'in 'korma.sql.fns/pred-in
'not-in 'korma.sql.fns/pred-not-in
'> 'korma.sql.fns/pred->
'< 'korma.sql.fns/pred-<
'>= 'korma.sql.fns/pred->=
Expand Down
1 change: 1 addition & 0 deletions src/korma/sql/fns.clj
Expand Up @@ -11,6 +11,7 @@
(defn pred-not [v] (wrapper "NOT" v))

(defn pred-in [k v] (infix k "IN" v))
(defn pred-not-in [k v] (infix k "NOT IN" v))
(defn pred-> [k v] (infix k ">" v))
(defn pred-< [k v] (infix k "<" v))
(defn pred->= [k v] (infix k ">=" v))
Expand Down
8 changes: 8 additions & 0 deletions test/korma/test/core.clj
Expand Up @@ -327,6 +327,14 @@
(exec)))
"SELECT MIN(\"the_table\".\"date_created\") \"start_date\", MAX(\"the_table\".\"date_created\") \"end_date\" FROM \"the_table\" WHERE (\"the_table\".\"id\" IN (?, ?, ?))")))

(deftest not-in
(defentity the_table)
(is (= (sql-only
(-> (select* the_table)
(where {:id [not-in [1 2 3]]})
(exec)))
"SELECT \"the_table\".* FROM \"the_table\" WHERE (\"the_table\".\"id\" NOT IN (?, ?, ?))")))

(deftest subselect-table-prefix
(defentity first_table)
(is (= (sql-only
Expand Down

0 comments on commit 4a55854

Please sign in to comment.