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

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

[nongnu] elpa/emacsql c8fceaf236 5/6: emacsql-sqlite-connection: New fun


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql c8fceaf236 5/6: emacsql-sqlite-connection: New function
Date: Sun, 17 Nov 2024 18:59:37 -0500 (EST)

branch: elpa/emacsql
commit c8fceaf236fc4b68e95160e0d4161a3e50a670ad
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    emacsql-sqlite-connection: New function
---
 emacsql-sqlite.el | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/emacsql-sqlite.el b/emacsql-sqlite.el
index 1d2433e053..38ca112ea2 100644
--- a/emacsql-sqlite.el
+++ b/emacsql-sqlite.el
@@ -97,6 +97,21 @@ See https://www.sqlite.org/c3ref/busy_timeout.html.";)
 
 ;;; Utilities
 
+(defun emacsql-sqlite-connection (variable file &optional setup)
+  "Return the connection stored in VARIABLE to the database in FILE.
+
+If the value of VARIABLE is a live database connection, return that.
+
+Otherwise open a new connection to the database in FILE and store the
+connection in VARIABLE, before returning it.  If FILE is nil, use an
+in-memory database.  Always enable support for foreign key constrains.
+If optional SETUP is non-nil, it must be a function, which takes the
+connection as only argument.  This function can be used to initialize
+tables, for example."
+  (or (let ((connection (symbol-value variable)))
+        (and connection (emacsql-live-p connection) connection))
+      (set variable (emacsql-sqlite-open file nil setup))))
+
 (defun emacsql-sqlite-open (file &optional debug setup)
   "Open a connection to the database stored in FILE using an SQLite back-end.
 



reply via email to

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