[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/emacsql 76bf0c34dc 038/427: Add rudimentary :where expande
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/emacsql 76bf0c34dc 038/427: Add rudimentary :where expander. |
Date: |
Tue, 13 Dec 2022 02:59:26 -0500 (EST) |
branch: elpa/emacsql
commit 76bf0c34dce3efb24702635a341b51b7f2e754ef
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>
Add rudimentary :where expander.
---
README.md | 5 ++---
emacsql.el | 15 +++++++++++++++
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index f288c265ee..f323cf7f88 100644
--- a/README.md
+++ b/README.md
@@ -28,9 +28,8 @@ Requires Emacs 24 or later.
(emacsql-insert db 'employees ["Jeff" 1000 60000.0]
["Susan" 1001 64000.0])
-;; The high-level SELECT interface is a work in progress.
-(emacsql-select-raw db (concat "SELECT name, id FROM employees "
- "WHERE salary > 60000;"))
+;; Query the database for results:
+(emacsql db [:select [name id] :from employees :where (> salary 60000)])
;; => (("Susan" 1001))
```
diff --git a/emacsql.el b/emacsql.el
index ebb62d31b8..ef6a7a0188 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -386,6 +386,21 @@ KIND should be :value or :identifier."
(list "FROM %s" (cons (emacsql-var table) :identifier))
(list (concat "FROM " (emacsql-escape-format table :identifier)))))
+(emacsql-defexpander :where (expr)
+ (let ((vars ()))
+ (cl-flet* ((collect (thing kind)
+ (push (cons (emacsql-var thing) kind) vars) "%s")
+ (handle (v)
+ (cond ((emacsql-var v) (collect v))
+ ((symbolp v) (emacsql-escape-format v :identifier))
+ ((emacsql-escape-value v)))))
+ (cl-destructuring-bind (op a b) expr
+ (cons (format "WHERE %s %s %s"
+ (handle a)
+ op
+ (handle b))
+ vars)))))
+
(provide 'emacsql)
;;; emacsql.el ends here
- [nongnu] elpa/emacsql 25f9817064 094/427: Add work-in-progress note back., (continued)
- [nongnu] elpa/emacsql 25f9817064 094/427: Add work-in-progress note back., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 03295cba37 119/427: Add ORDER BY expanders., ELPA Syncer, 2022/12/13
- [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 <=
- [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, 2022/12/13
- [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