[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)))))
- [nongnu] elpa/emacsql ff4c59a2a7 113/427: Fix cl-lib mistake., (continued)
- [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, 2022/12/13
- [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 <=
- [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
- [nongnu] elpa/emacsql 935cca89a9 176/427: Add updated information about Windows., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql b3aea1e6af 055/427: Oops, fix >= back., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql c4396ec5e6 057/427: Fix a bunch of warnings., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql e9fbc4a913 061/427: Fill out a Makefile., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 829298d5a7 063/427: Add dependency listing., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 231ec586ca 088/427: Drop forced process coding system., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql eba26bead6 102/427: Add emacsql-compile function for debugging., ELPA Syncer, 2022/12/13