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

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

[nongnu] elpa/emacsql a1ce9f16f2 097/427: Add emacsql-with-connection ba


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql a1ce9f16f2 097/427: Add emacsql-with-connection back in.
Date: Tue, 13 Dec 2022 02:59:31 -0500 (EST)

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

    Add emacsql-with-connection back in.
---
 emacsql.el | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/emacsql.el b/emacsql.el
index c746e4e276..1983ca6ab6 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -128,6 +128,21 @@ buffer. This is for debugging purposes."
     (when (and process (process-live-p process))
       (process-send-string process ".exit\n"))))
 
+(defmacro emacsql-with-connection (conn-spec &rest body)
+  "Open an Emacsql connection, evaluate BODY, and close the connection.
+CONN-SPEC is a connection specification like the call to
+`emacsql-connect', establishing a single binding.
+
+  (emacsql-with-connection (db \"company.db\")
+    (emacsql db [:create-table foo [x]])
+    (emacsql db [:insert :into foo :values ([1] [2] [3])])
+    (emacsql db [:select * :from foo]))"
+  (declare (indent 1))
+  `(let ((,(car conn-spec) (emacsql-connect ,@(cdr conn-spec))))
+     (unwind-protect
+         (progn ,@body)
+       (emacsql-close ,(car conn-spec)))))
+
 (defun emacsql-buffer (conn)
   "Get proccess buffer for CONN."
   (process-buffer (emacsql-process conn)))



reply via email to

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