emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/emacsql 8123020ca7 153/427: Make and and or operators vari


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql 8123020ca7 153/427: Make and and or operators variadic.
Date: Tue, 13 Dec 2022 02:59:37 -0500 (EST)

branch: elpa/emacsql
commit 8123020ca773d373d26bb7faefbbb7f8631358e6
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>

    Make and and or operators variadic.
---
 emacsql-tests.el | 13 +++++++++++++
 emacsql.el       | 11 ++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/emacsql-tests.el b/emacsql-tests.el
index 763a014d0f..3e109788db 100644
--- a/emacsql-tests.el
+++ b/emacsql-tests.el
@@ -163,6 +163,19 @@
     ([:values [a $$1]] '()
      "VALUES ('a', '$1');")))
 
+(ert-deftest emacsql-expr ()
+  (emacsql-tests-with-queries
+    ([:where (and)] '()
+     "WHERE 1;")
+    ([:where (or)] '()
+     "WHERE 0;")
+    ([:where (and a b)] '()
+     "WHERE a AND b;")
+    ([:where (or a $1)] '(b)
+     "WHERE a OR b;")
+    ([:where (and $1 $2 $3)] '(a b c)
+     "WHERE a AND b AND c;")))
+
 (ert-deftest emacsql-transaction ()
   (emacsql-tests-with-queries
     ([:begin :transaction] '()
diff --git a/emacsql.el b/emacsql.el
index f9de57cc91..df5ed36084 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -532,7 +532,7 @@ definitions for return from a `emacsql-defexpander'."
                            (recur (if (eq op '>=) 2 0))
                            (recur (if (eq op '>=) 0 2))))))
              ;; Binary
-             ((< > = != like glob is and or * / % << >> + & | as)
+             ((< > = != like glob is * / % << >> + & | as)
               (if (= 2 (length args))
                   (format "%s %s %s"
                           (recur 0)
@@ -549,6 +549,15 @@ definitions for return from a `emacsql-defexpander'."
               (cl-ecase (length args)
                 (1 (format "-(%s)" (recur 0)))
                 (2 (format "%s - %s" (recur 0) (recur 1)))))
+             ;; variadic
+             ((and or)
+              (cl-case (length args)
+                (0 (if (eq op 'and) "1" "0"))
+                (1 (recur 0))
+                (otherwise
+                 (mapconcat
+                  #'recur (cl-loop for i from 0 below (length args) collect i)
+                  (format " %s " (upcase (symbol-name op)))))))
              ;; quote special case
              ((quote)
               (cl-ecase (length args)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]