branch: elpa/emacsql commit 672963ae533cb30f57774ab80ae20567cb26f89b Author: Christopher Wellons <well...@nullprogram.com> Commit: Christopher Wellons <well...@nullprogram.com>
Add DISTINCT option to :select. --- README.md | 3 ++- emacsql-compiler.el | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 885aa8380c..dd81a92cf6 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ Provides `DROP TABLE`. [:drop-table employees] ``` -#### :select `<column-spec>` +#### :select `<column-spec>|(:distinct <column-spec>)` Provides `SELECT`. `column-spec` can be a `*` symbol or a vector of column identifiers, optionally as expressions. @@ -199,6 +199,7 @@ column identifiers, optionally as expressions. ```el [:select [name (/ salary 52)] ...] [:select [(as name n) (as age a)] ...] +[:select (:distinct [name age id]) ...] ``` #### :from `<table>` diff --git a/emacsql-compiler.el b/emacsql-compiler.el index db24fbb9f0..0d21aa7554 100644 --- a/emacsql-compiler.el +++ b/emacsql-compiler.el @@ -374,9 +374,17 @@ definitions for return from a `emacsql-defexpander'." (emacsql-defexpander :select (arg) "Expands to the SELECT keyword." (emacsql-with-vars "SELECT " - (if (eq '* arg) - "*" - (idents arg)))) + (cond ((eq '* arg) + "*") + ((listp arg) + (cl-case (length arg) + (1 (idents (car arg))) + (2 (cl-case (car arg) + (:distinct (concat "DISTINCT " (idents (cadr arg)))) + (:all (concat "ALL " (idents (cadr arg)))) + (otherwise (emacsql-error "Invalid SELECT: %S" (car arg))))) + (otherwise (emacsql-error "Invalid SELECT idents: %S" arg)))) + ((idents arg))))) (emacsql-defexpander :from (sources) "Expands to the FROM keyword."