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

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

[nongnu] elpa/emacsql 530b0ad98c 151/427: Allow arbitrary sub-statements


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql 530b0ad98c 151/427: Allow arbitrary sub-statements.
Date: Tue, 13 Dec 2022 02:59:37 -0500 (EST)

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

    Allow arbitrary sub-statements.
---
 emacsql.el | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/emacsql.el b/emacsql.el
index 3449777253..0056f4050c 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -309,6 +309,18 @@ a list of (<string> [arg-pos] ...)."
   (declare (indent 2))
   `(emacsql-add-expander ,keyword ,(length args) (lambda ,args ,@body)))
 
+(defun emacsql-sql-p (thing)
+  "Return non-nil if THING looks like a :select."
+  (and (sequencep thing)
+       (or (not (null (assoc (elt thing 0) emacsql-expanders)))
+           (emacsql-sql-p (elt thing 0)))))
+
+(defun emacsql-get-expander (keyword)
+  "Return the expander with arity for KEYWORD."
+  (if (emacsql-sql-p keyword)
+      (list 0 (lambda () (emacsql-expand keyword :subsql-p)))
+    (cdr (assoc keyword emacsql-expanders))))
+
 (defun emacsql-expand (sql &optional subsql-p)
   "Expand SQL into a SQL-consumable string, with variables."
   (let* ((cache emacsql-expander-cache)
@@ -317,7 +329,7 @@ a list of (<string> [arg-pos] ...)."
         (cl-loop with items = (cl-coerce sql 'list)
                  while (not (null items))
                  for keyword = (pop items)
-                 for (arity expander) = (cdr (assoc keyword emacsql-expanders))
+                 for (arity expander) = (emacsql-get-expander keyword)
                  when expander
                  collect (apply expander (cl-subseq items 0 arity)) into parts
                  else do (error "Unrecognized keyword %s" keyword)
@@ -506,7 +518,7 @@ definitions for return from a `emacsql-defexpander'."
   "Expand EXPR recursively."
   (emacsql-with-vars ""
     (cond
-     ((and (sequencep expr) (eq :select (elt expr 0))) (subsql expr))
+     ((emacsql-sql-p expr) (subsql expr))
      ((atom expr) (var expr :auto))
      ((cl-destructuring-bind (op . args) expr
          (cl-flet ((recur (n) (combine (emacsql--expr (nth n args)))))



reply via email to

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