all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] ob-sqlite: Use a transient in-memory database by default
@ 2023-05-03 12:59 Rudolf Adamkovič
  2023-05-03 15:12 ` Max Nikulin
  0 siblings, 1 reply; 22+ messages in thread
From: Rudolf Adamkovič @ 2023-05-03 12:59 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Rudolf Adamkovič

* etc/ORG-NEWS (New features): Add a news entry.
* lisp/ob-sqlite.el (org-babel-execute: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                   |  6 ++++++
 lisp/ob-sqlite.el              |  3 +--
 testing/lisp/test-ob-sqlite.el | 36 ++++++++++++++++++++++++++++++++--
 3 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 03894f128..42bfc2be0 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -181,6 +181,12 @@ official [[https://clojure.org/guides/deps_and_cli][Clojure CLI tools]].
 The command can be customized with ~ob-clojure-cli-command~.
 
 ** New features
+*** Make =ob-sqlite= use in-database by default
+
+SQLite source blocks with no =:db= argument now execute against a
+transient in-memory database.  This makes SQLite source blocks more
+practical, and it matches the default behavior of the =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..60da488f7 100644
--- a/lisp/ob-sqlite.el
+++ b/lisp/ob-sqlite.el
@@ -66,7 +66,7 @@
   "Execute a block of Sqlite code with Babel.
 This function is called by `org-babel-execute-src-block'."
   (let ((result-params (split-string (or (cdr (assq :results params)) "")))
-	(db (cdr (assq :db params)))
+	(db (or (cdr (assq :db params)) ":memory:"))
 	(separator (cdr (assq :separator params)))
 	(nullvalue (cdr (assq :nullvalue params)))
 	(headers-p (equal "yes" (cdr (assq :colnames params))))
@@ -74,7 +74,6 @@ This function is called by `org-babel-execute-src-block'."
 			   (lambda (arg) (car (assq arg params)))
 			   (list :header :echo :bail :column
 				 :csv :html :line :list)))))
-    (unless db (error "ob-sqlite: can't evaluate without a database"))
     (with-temp-buffer
       (insert
        (org-babel-eval
diff --git a/testing/lisp/test-ob-sqlite.el b/testing/lisp/test-ob-sqlite.el
index 72d75c9b7..b76a82d98 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.40.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2023-08-12  9:39 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-03 12:59 [PATCH] ob-sqlite: Use a transient in-memory database by default Rudolf Adamkovič
2023-05-03 15:12 ` Max Nikulin
2023-05-03 16:32   ` Max Nikulin
2023-05-04 10:27     ` Ihor Radchenko
2023-05-06 20:40     ` Rudolf Adamkovič
2023-05-07 14:45       ` Max Nikulin
2023-06-13  9:59       ` Ihor Radchenko
2023-06-19 12:42         ` Rudolf Adamkovič
2023-06-20 10:58           ` Ihor Radchenko
2023-08-03 12:35             ` Rudolf Adamkovič
2023-08-04  8:08               ` Ihor Radchenko
2023-08-04 22:57                 ` Rudolf Adamkovič
2023-08-05  3:00                   ` Max Nikulin
2023-08-06  0:22                     ` Rudolf Adamkovič
2023-08-12  8:22                       ` Ihor Radchenko
2023-08-12  9:38                       ` Max Nikulin
2023-08-05  3:06                   ` [accessibility] worg obscures text (Re: [PATCH] ob-sqlite: Use a transient in-memory database by default) Max Nikulin
2023-08-05  3:20                     ` Samuel Wales
2023-08-05  3:22                       ` Samuel Wales
2023-08-10 16:13                         ` Max Nikulin
2023-08-10 23:35                           ` Samuel Wales
2023-08-05  9:14                   ` [PATCH] ob-sqlite: Use a transient in-memory database by default Ihor Radchenko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.