Fixes #553 by adding :not-between
This commit is contained in:
parent
21ce3a2242
commit
b2c1ae0068
2 changed files with 17 additions and 10 deletions
|
|
@ -93,7 +93,7 @@ and a time zone name or identifier (can be a string, a symbol, or a keyword):
|
|||
The time zone name or identifier will be inlined (as a string) and therefore
|
||||
cannot be an expression.
|
||||
|
||||
## between
|
||||
## between and not-between
|
||||
|
||||
Accepts three arguments: an expression, a lower bound, and
|
||||
an upper bound:
|
||||
|
|
@ -101,6 +101,9 @@ an upper bound:
|
|||
```clojure
|
||||
(sql/format-expr [:between :id 1 100])
|
||||
;;=> ["id BETWEEN ? AND ?" 1 100]
|
||||
|
||||
(sql/format-expr [:not-between :id 1 100])
|
||||
;;=> ["id NOT BETWEEN ? AND ?" 1 100]
|
||||
```
|
||||
|
||||
## case
|
||||
|
|
|
|||
|
|
@ -1877,6 +1877,17 @@
|
|||
(into paramsx)
|
||||
(into params))))
|
||||
|
||||
(defn- between-fn
|
||||
"For both :between and :not-between"
|
||||
[k [x a b]]
|
||||
(let [[sql-x & params-x] (format-expr x {:nested true})
|
||||
[sql-a & params-a] (format-expr a {:nested true})
|
||||
[sql-b & params-b] (format-expr b {:nested true})]
|
||||
(-> [(str sql-x " " (sql-kw k) " " sql-a " AND " sql-b)]
|
||||
(into params-x)
|
||||
(into params-a)
|
||||
(into params-b))))
|
||||
|
||||
(defn ignore-respect-nulls [k [x]]
|
||||
(let [[sql & params] (format-expr x)]
|
||||
(into [(str sql " " (sql-kw k))] params)))
|
||||
|
|
@ -1938,15 +1949,8 @@
|
|||
(binding [*inline* true]
|
||||
(format-expr (if (ident? tz) (name tz) tz)))]
|
||||
(into [(str sql " AT TIME ZONE " tz-sql)] params)))
|
||||
:between
|
||||
(fn [_ [x a b]]
|
||||
(let [[sql-x & params-x] (format-expr x {:nested true})
|
||||
[sql-a & params-a] (format-expr a {:nested true})
|
||||
[sql-b & params-b] (format-expr b {:nested true})]
|
||||
(-> [(str sql-x " BETWEEN " sql-a " AND " sql-b)]
|
||||
(into params-x)
|
||||
(into params-a)
|
||||
(into params-b))))
|
||||
:between #'between-fn
|
||||
:not-between #'between-fn
|
||||
:case #'case-clauses
|
||||
:case-expr #'case-clauses
|
||||
:cast
|
||||
|
|
|
|||
Loading…
Reference in a new issue