branch: elpa/emacsql
commit 58e31aa3a9f888e197f086060ce5c6cabcd168e6
Author: Christopher Wellons <[email protected]>
Commit: Christopher Wellons <[email protected]>
Add :update and :set expanders.
---
README.md | 17 +++++++++++++++++
emacsql-tests.el | 4 +++-
emacsql.el | 10 ++++++++++
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 6e95635e4c..d40356bc83 100644
--- a/README.md
+++ b/README.md
@@ -168,6 +168,23 @@ Provides `INSERT`.
[:insert :into employees :values (["Jeff" 0] ["Susan" 0])]
```
+#### :update `<table>`
+
+Provides `UPDATE`.
+
+```el
+[:update people :set ...]
+```
+
+#### :set `<assignment>|[<assignment> ...]`
+
+Provides `SET`.
+
+```el
+[:update people :set (= name "Richy") :where ...]
+[:update people :set [(= name "Ricky") (= salary 300000)] :where ...]
+```
+
### Templates
To make statement compilation faster, and to avoid making you build up
diff --git a/emacsql-tests.el b/emacsql-tests.el
index 42adb83255..41ebd4eb74 100644
--- a/emacsql-tests.el
+++ b/emacsql-tests.el
@@ -63,7 +63,9 @@
(emacsql-tests-query [:create-table foo [a b c]] ()
"CREATE TABLE foo (a, b, c);")
(emacsql-tests-query [:drop-table $1] '(foo)
- "DROP TABLE foo;"))
+ "DROP TABLE foo;")
+ (emacsql-tests-query [:update people :set (= id $1)] '(10)
+ "UPDATE people SET id = 10;"))
(provide 'emacsql-tests)
diff --git a/emacsql.el b/emacsql.el
index cd75907f7b..c378d65cf3 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -472,6 +472,16 @@ definitions for return from a `emacsql-defexpander'."
(emacsql-with-vars "VALUES "
(var values :vector)))
+(emacsql-defexpander :update (table)
+ (emacsql-with-vars "UPDATE "
+ (var table :identifier)))
+
+(emacsql-defexpander :set (set)
+ (emacsql-with-vars "SET "
+ (cl-etypecase set
+ (vector (mapconcat (lambda (s) (combine (emacsql--expr s))) set ", "))
+ (list (combine (emacsql--expr set))))))
+
(provide 'emacsql)
;;; emacsql.el ends here