branch: elpa/emacsql commit fe0c7004fc0c021bc94c8d0ebe60c8455aacfa2d Author: Christopher Wellons <well...@nullprogram.com> Commit: Christopher Wellons <well...@nullprogram.com>
Add :begin, :commit, and :rollback. --- README.md | 19 +++++++++++++++++++ emacsql-tests.el | 11 +++++++++++ emacsql.el | 14 ++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/README.md b/README.md index f8a0ff9e8d..4d6dcb0ac0 100644 --- a/README.md +++ b/README.md @@ -287,6 +287,25 @@ Provides `UNION`, `UNION ALL`, `DIFFERENCE`, and `EXCEPT`. [:select * :from sales :union :select * :from accounting] ``` +#### :begin `<:transaction|:immediate|:deferred|:exclusive>` + +Provides `BEGIN`. Exactly one of these "arguments" must always be +supplied. `:deferred` and `:transaction` are aliases. + +```el +[:begin :transaction] +[:begin :immediate] +``` + +#### :commit, :rollback + +Provides `COMMIT` and `ROLLBACK`. + +```el +[:commit] +[:rollback] +``` + #### :pragma `<expr>` Provides `PRAGMA`. diff --git a/emacsql-tests.el b/emacsql-tests.el index b4edd8c2bb..cb383f563f 100644 --- a/emacsql-tests.el +++ b/emacsql-tests.el @@ -163,6 +163,17 @@ ([:values [a $$1]] '() "VALUES ('a', '$1');"))) +(ert-deftest emacsql-transaction () + (emacsql-tests-with-queries + ([:begin :transaction] '() + "BEGIN TRANSACTION;") + ([:begin :immediate] '() + "BEGIN IMMEDIATE;") + ([:rollback] '() + "ROLLBACK;") + ([:commit] '() + "COMMIT;"))) + (ert-deftest emacsql-system () "A short test that fully interacts with SQLite." (should-not (emacsql-sqlite3-unavailable-p)) diff --git a/emacsql.el b/emacsql.el index e995f8bce4..6cff8a905a 100644 --- a/emacsql.el +++ b/emacsql.el @@ -690,6 +690,20 @@ definitions for return from a `emacsql-defexpander'." (emacsql-with-vars "PRAGMA " (expr expr))) +(emacsql-defexpander :begin (kind) + (emacsql-with-vars "BEGIN " + (cl-ecase kind + (:transaction "TRANSACTION") + (:deferred "DEFERRED") + (:immediate "IMMEDIATE") + (:exclusive "EXCLUSIVE")))) + +(emacsql-defexpander :commit () + (list "COMMIT")) + +(emacsql-defexpander :rollback () + (list "ROLLBACK")) + (provide 'emacsql) ;;; emacsql.el ends here