branch: elpa/emacsql commit 03295cba37ff1053e81763191832a5cc91bd2289 Author: Christopher Wellons <well...@nullprogram.com> Commit: Christopher Wellons <well...@nullprogram.com>
Add ORDER BY expanders. --- README.md | 9 +++++++++ emacsql.el | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 55654a5b91..6e71467091 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,15 @@ Provides `GROUP BY`. [... :group-by name] ``` +#### :ascending-by <expr>, :descending-by <expr> + +Provides `ORDER BY`. + +```el +[... :ascending-by date] +[... :descending-by [width height]] +``` + #### :insert, :replace Provides `INSERT`, `REPLACE`. diff --git a/emacsql.el b/emacsql.el index 0211a07a10..70cf4e673c 100644 --- a/emacsql.el +++ b/emacsql.el @@ -528,6 +528,14 @@ definitions for return from a `emacsql-defexpander'." (emacsql-with-vars "GROUP BY " (combine (emacsql--expr expr)))) +(emacsql-defexpander :ascending-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"))) + (emacsql-defexpander :create-table (table schema) (emacsql-with-vars "CREATE " (let (temporary if-not-exists name)