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

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

[nongnu] elpa/emacsql 75ac0448a5 364/427: Add support for DISTINCT in ag


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql 75ac0448a5 364/427: Add support for DISTINCT in aggregate functions (#41)
Date: Tue, 13 Dec 2022 03:00:11 -0500 (EST)

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

    Add support for DISTINCT in aggregate functions (#41)
    
    Example:
    
        [:select (funcall count :distinct x) :from foo]
    
    Ref: https://www.sqlite.org/lang_aggfunc.html
---
 emacsql-compiler.el             | 14 +++++++++-----
 tests/emacsql-compiler-tests.el | 13 +++++++++++++
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/emacsql-compiler.el b/emacsql-compiler.el
index 2885152c44..e8f3365759 100644
--- a/emacsql-compiler.el
+++ b/emacsql-compiler.el
@@ -294,13 +294,17 @@ Only use within `emacsql-with-params'!"
             ;; Special case funcall
             ((funcall)
              (format "%s(%s)" (recur 0)
-                     (if (and (= 2 (length args))
-                              (eq '* (nth 1 args)))
-                         "*"
-                       (mapconcat
+                     (cond
+                      ((and (= 2 (length args))
+                            (eq '* (nth 1 args)))
+                       "*")
+                      ((and (= 3 (length args))
+                            (eq :distinct (nth 1 args))
+                            (format "DISTINCT %s" (recur 2))))
+                      ((mapconcat
                         #'recur (cl-loop for i from 1 below (length args)
                                          collect i)
-                        ", "))))
+                        ", ")))))
             ;; Guess
             (otherwise
              (mapconcat
diff --git a/tests/emacsql-compiler-tests.el b/tests/emacsql-compiler-tests.el
index bed49c8889..cb92ee04d6 100644
--- a/tests/emacsql-compiler-tests.el
+++ b/tests/emacsql-compiler-tests.el
@@ -216,6 +216,19 @@
    ([:alter-table foo :add-column size :integer :not-null] '()
     "ALTER TABLE foo ADD COLUMN size INTEGER NOT NULL;")))
 
+(ert-deftest emacsql-funcall ()
+  (emacsql-tests-with-queries
+   ([:select (funcall count x)] '()
+    "SELECT count(x);")
+   ([:select (funcall count *)] '()
+    "SELECT count(*);")
+   ([:select (funcall group-concat x y)] '()
+    "SELECT group_concat(x, y);")
+   ([:select (funcall foobar :distinct x y)] '()
+    "SELECT foobar(':distinct', x, y);")
+   ([:select (funcall count :distinct x)] '()
+    "SELECT count(DISTINCT x);")))
+
 (provide 'emacsql-compiler-tests)
 
 ;;; emacsql-tests.el ends here



reply via email to

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