branch: elpa/emacsql commit a1ce9f16f2a6dcd13de6c3e4d6e1df04ed387c2b Author: Christopher Wellons <well...@nullprogram.com> Commit: Christopher Wellons <well...@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)))