branch: elpa/emacsql
commit c9aab20d476ca9dd67cbbb0ddedcafc23a59c197
Author: Christopher Wellons <[email protected]>
Commit: Christopher Wellons <[email protected]>
Add in operator (special case operator).
---
README.md | 2 +-
emacsql-tests.el | 4 +++-
emacsql.el | 7 ++++++-
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 7e232caa20..89b8603025 100644
--- a/README.md
+++ b/README.md
@@ -69,7 +69,7 @@ exactly like so in a structured Emacsql statement.
* / % + - << >> &
| < <= > >= = !=
- is like glob and or
+ is like glob and or in
The `<=` and `>=` operators accept 2 or 3 operands, transforming into
a SQL `_ BETWEEN _ AND _` operator as appropriate.
diff --git a/emacsql-tests.el b/emacsql-tests.el
index 41ebd4eb74..ac96be14b2 100644
--- a/emacsql-tests.el
+++ b/emacsql-tests.el
@@ -65,7 +65,9 @@
(emacsql-tests-query [:drop-table $1] '(foo)
"DROP TABLE foo;")
(emacsql-tests-query [:update people :set (= id $1)] '(10)
- "UPDATE people SET id = 10;"))
+ "UPDATE people SET id = 10;")
+ (emacsql-tests-query [:select * :from people :where (in name $1)] '([FOO
BAR])
+ "SELECT * FROM people WHERE name IN ('FOO', 'BAR');"))
(provide 'emacsql-tests)
diff --git a/emacsql.el b/emacsql.el
index 4ba13c93c3..1fde40847e 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -426,7 +426,12 @@ definitions for return from a `emacsql-defexpander'."
((-)
(cl-ecase (length args)
(1 (format "-(%s)" (recur 0)))
- (2 (format "%s - %s" (recur 0) (recur 1)))))))))))
+ (2 (format "%s - %s" (recur 0) (recur 1)))))
+ ;; IN special case
+ ((in)
+ (if (= 2 (length args))
+ (format "%s IN %s" (recur 0)
+ (var (nth 1 args) :vector))))))))))
;; SQL Expansion Functions: