From 144bd75183a9185786248d9404ddeee4b93ed30f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= Date: Wed, 3 May 2023 14:59:03 +0200 Subject: [PATCH] ob-sqlite: Use a transient in-memory database by default * etc/ORG-NEWS (New features): Add a news entry. * lisp/ob-sqlite.el (org-babel-default-header-args:sqlite): Default ':db' to ":memory:". * testing/lisp/test-ob-sqlite.el (ob-sqlite/in-file): Test the old behavior. * testing/lisp/test-ob-sqlite.el (ob-sqlite/in-memory): Test the new behavior. --- etc/ORG-NEWS | 8 ++++++++ lisp/ob-sqlite.el | 2 +- testing/lisp/test-ob-sqlite.el | 36 ++++++++++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 4f16eda24..569ec651b 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -489,6 +489,14 @@ Final hooks are added to the following commands: The prefix arguments are passed to ~org-insert-todo-heading~. +*** Make ~ob-sqlite~ use in-memory databases by default + +The ~:db~ header argument of ~sqlite~ source blocks now defaults to +~":memory:"~ which stands for a temporary in-memory database. As a +result, ~sqlite~ source blocks are usable out of the box, with no +header arguments, matching the behavior and practicality of the +official ~sqlite3~ shell. + *** Add support for ~logind~ idle time in ~org-user-idle-seconds~ When Emacs is built with =dbus= support and diff --git a/lisp/ob-sqlite.el b/lisp/ob-sqlite.el index 526b73ebd..75ef50913 100644 --- a/lisp/ob-sqlite.el +++ b/lisp/ob-sqlite.el @@ -39,7 +39,7 @@ (declare-function orgtbl-to-csv "org-table" (table params)) (declare-function org-table-to-lisp "org-table" (&optional txt)) -(defvar org-babel-default-header-args:sqlite '()) +(defvar org-babel-default-header-args:sqlite '((:db . ":memory:"))) (defvar org-babel-header-args:sqlite '((db . :any) diff --git a/testing/lisp/test-ob-sqlite.el b/testing/lisp/test-ob-sqlite.el index 72d75c9b7..621a11b0b 100644 --- a/testing/lisp/test-ob-sqlite.el +++ b/testing/lisp/test-ob-sqlite.el @@ -39,8 +39,40 @@ .import $tb TestTable select * from TestTable; #+end_src" - (org-babel-next-src-block) - (org-babel-execute-src-block))))) + (org-babel-next-src-block) + (org-babel-execute-src-block))))) + +(ert-deftest ob-sqlite/in-memory () + "Test in-memory temporariness." + (should + (equal 0 + (progn + (org-test-with-temp-text + "#+BEGIN_SRC sqlite +PRAGMA user_version = 1; +#+END_SRC" + (org-babel-execute-src-block)) + (org-test-with-temp-text + "#+BEGIN_SRC sqlite +PRAGMA user_version; +#+END_SRC" + (org-babel-execute-src-block)))))) + +(ert-deftest ob-sqlite/in-file () + "Test in-file permanency." + (should + (equal 1 + (let ((file (org-babel-temp-file "test" ".sqlite"))) + (org-test-with-temp-text + (format "#+BEGIN_SRC sqlite :db %s +PRAGMA user_version = 1; +#+END_SRC" file) + (org-babel-execute-src-block)) + (org-test-with-temp-text + (format "#+BEGIN_SRC sqlite :db %s +PRAGMA user_version; +#+END_SRC" file) + (org-babel-execute-src-block)))))) (provide 'test-ob-sqlite) ;;; test-ob-sqlite.el ends here -- 2.37.1 (Apple Git-137.1)