[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/emacsql 72145a1627 045/427: Allow for multi-arity keyword
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/emacsql 72145a1627 045/427: Allow for multi-arity keyword expanders. |
Date: |
Tue, 13 Dec 2022 02:59:26 -0500 (EST) |
branch: elpa/emacsql
commit 72145a16279a51c2f24263ffbed15822f0918fcf
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>
Allow for multi-arity keyword expanders.
---
emacsql.el | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/emacsql.el b/emacsql.el
index ab39fa7c8d..cbf2634fb6 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -295,24 +295,30 @@ Each row must be a sequence of values to store into TABLE.
(defvar emacsql-expanders ()
"Alist of all expansion functions.")
-(defun emacsql-add-expander (keyword function)
+(defun emacsql-add-expander (keyword arity function)
"Register FUNCTION for KEYWORD as a SQL expander.
-FUNCTION should accept a single argument, the keyword's argument,
-and should return a list of (<string> [arg-pos] ...)."
+FUNCTION should accept the keyword's arguments and should return
+a list of (<string> [arg-pos] ...).
+
+See also `emacsql-with-errors'."
(prog1 keyword
- (push (cons keyword function) emacsql-expanders)))
+ (push (list keyword arity function) emacsql-expanders)))
(defmacro emacsql-defexpander (keyword args &rest body)
"Define an expander for KEYWORD."
(declare (indent 2))
- `(emacsql-add-expander ,keyword (lambda ,args ,@body)))
+ `(emacsql-add-expander ,keyword ,(length args) (lambda ,args ,@body)))
(defun emacsql-expand (sql)
"Expand SQL into a SQL-consumable string, with variables."
- (loop for (keyword argument) on (cl-coerce sql 'list) by #'cddr
- for expander = (cdr (assoc keyword emacsql-expanders))
- when expander collect (funcall expander argument) into parts
+ (loop with items = (cl-coerce sql 'list)
+ while (not (null items))
+ for keyword = (pop items)
+ for (arity expander) = (cdr (assoc keyword emacsql-expanders))
+ when expander
+ collect (apply expander (subseq items 0 arity)) into parts
else do (error "Unrecognized keyword %s" keyword)
+ do (setf items (subseq items arity))
finally (return (cons (concat (mapconcat #'car parts " ") ";")
(apply #'nconc (mapcar #'cdr parts))))))
- [nongnu] elpa/emacsql d1c0904564 120/427: Fix missing quotes., (continued)
- [nongnu] elpa/emacsql d1c0904564 120/427: Fix missing quotes., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 4718ff4e89 122/427: Simplify all the expanders with new local functions., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 54247e4b5e 127/427: Add another insertion unit test., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql aa9283ca0a 132/427: Allow sub-selects with :from., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql c236aa8437 144/427: Remove extra space., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 75ea77c9a0 149/427: Add an "as" operator, greatly simplifying :from., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 213bb71b7a 152/427: Add :having expander., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 8123020ca7 153/427: Make and and or operators variadic., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 76bf0c34dc 038/427: Add rudimentary :where expander., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql afe64ca63a 040/427: Fix emacsql-add-expander example., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 72145a1627 045/427: Allow for multi-arity keyword expanders.,
ELPA Syncer <=
- [nongnu] elpa/emacsql f54142f1eb 062/427: Argument list checking in emacsql-format., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 86687b6ba3 067/427: Flesh out more README., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql a306de980a 070/427: Add :delete keyword., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql afa9aa5194 072/427: Add :into expander., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 8f59fe6e80 073/427: Add a vector escape., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql eb3283990e 077/427: Drop emacsql-create., ELPA Syncer, 2022/12/13
- [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