[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/emacsql b2d83c6477 123/427: Fix up ORDER BY, drop :ascendi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/emacsql b2d83c6477 123/427: Fix up ORDER BY, drop :ascending-by. |
Date: |
Tue, 13 Dec 2022 02:59:34 -0500 (EST) |
branch: elpa/emacsql
commit b2d83c6477fc120dc4b98d7897bf5b4087b95cd1
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>
Fix up ORDER BY, drop :ascending-by.
---
README.md | 7 ++++---
emacsql-tests.el | 7 +++++++
emacsql.el | 20 ++++++++++++++------
3 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
index 9675a6fdca..0c8f789266 100644
--- a/README.md
+++ b/README.md
@@ -160,13 +160,14 @@ Provides `GROUP BY`.
[... :group-by name]
```
-#### :ascending-by `<expr>`, :descending-by `<expr>`
+#### :order-by `<expr>|(<expr> <:asc|:desc>)|[<expr> ...]`
Provides `ORDER BY`.
```el
-[... :ascending-by date]
-[... :descending-by [width height]]
+[... :order-by date]
+[... :order-by [(width :asc) (height :desc)]]
+[... :order-by [(width :asc) (- height)]]
```
#### :insert, :replace
diff --git a/emacsql-tests.el b/emacsql-tests.el
index 5744e3c3a2..867678aef9 100644
--- a/emacsql-tests.el
+++ b/emacsql-tests.el
@@ -74,6 +74,13 @@
(emacsql-tests-query [:create-table (:temporary :if-not-exists x) [y]] '()
"CREATE TEMPORARY TABLE IF NOT EXISTS x (y);"))
+(ert-deftest emacsql-order-by ()
+ (emacsql-tests-query [:order-by foo] '() "ORDER BY foo;")
+ (emacsql-tests-query [:order-by [$1]] '(bar) "ORDER BY bar;")
+ (emacsql-tests-query [:order-by (- foo)] '() "ORDER BY -(foo);")
+ (emacsql-tests-query [:order-by [(a :asc) ((/ b 2) :desc)]] '()
+ "ORDER BY a ASC, b / 2 DESC;"))
+
(ert-deftest emacsql-system ()
(should-not (emacsql-sqlite3-unavailable-p))
(emacsql-with-connection (db nil)
diff --git a/emacsql.el b/emacsql.el
index 9b428ab93f..1deea2ede0 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -535,13 +535,21 @@ definitions for return from a `emacsql-defexpander'."
(emacsql-with-vars "GROUP BY "
(expr expr)))
-(emacsql-defexpander :ascending-by (columns)
+(emacsql-defexpander :order-by (columns)
(emacsql-with-vars "ORDER BY "
- (concat (combine (emacsql--idents columns)) " ASC")))
-
-(emacsql-defexpander :descending-by (columns)
- (emacsql-with-vars "ORDER BY "
- (concat (combine (emacsql--idents columns)) " DESC")))
+ (cl-flet ((order (k) (cl-ecase k (:asc " ASC") (:desc " DESC"))))
+ (if (not (vectorp columns))
+ (expr columns)
+ (cl-loop for column across columns collect
+ (cl-etypecase column
+ (list (let ((kpos (cl-position-if #'keywordp column)))
+ (if kpos
+ (concat (expr (nth (- 1 kpos) column))
+ (order (nth kpos column)))
+ (expr column))))
+ (symbol (var column :identifier)))
+ into parts
+ finally (cl-return (mapconcat #'identity parts ", ")))))))
(emacsql-defexpander :create-table (table schema)
(emacsql-with-vars "CREATE "
- [nongnu] elpa/emacsql 66df2afbf1 091/427: Simplify start-process call., (continued)
- [nongnu] elpa/emacsql 66df2afbf1 091/427: Simplify start-process call., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql e956d91f99 095/427: Add -identifier to emacsql-escape., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 8aade12994 101/427: Add a unit test for vector update., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql beb0e00b9e 100/427: Rename emacsql--vars-collect., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql ee2877dab0 106/427: Clearer error message from escape identifier., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql e9b77b4774 112/427: Add a test for CREATE TABLE., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 652847dbf5 110/427: Allow memoization cache to be nil (for development)., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql ff4c59a2a7 113/427: Fix cl-lib mistake., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql f794d4d38f 116/427: Allow for selected columns in :insert-into., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql cefe1ec014 121/427: Add emacsql-sqlite3-unavailable-p., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql b2d83c6477 123/427: Fix up ORDER BY, drop :ascending-by.,
ELPA Syncer <=
- [nongnu] elpa/emacsql f52af86b05 124/427: Break apart and organize compilation tests., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 0bff8ccc34 126/427: Fix up README., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql a362a97c98 136/427: Add README section on foreign keys., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 223db2d397 141/427: Add quote operator., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 8951084b40 143/427: Add variable escaping., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 19a65f390e 147/427: Add ignored features section to README., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 530b0ad98c 151/427: Allow arbitrary sub-statements., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 3012f5b725 154/427: Fix typo., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 301e2ff4b6 175/427: Drop "simple" from helper method names., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 578a71d2d8 157/427: Re-order some definitions to group them., ELPA Syncer, 2022/12/13