[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.
- [nongnu] elpa/emacsql updated (be76529215 -> 937d45a1c3), ELPA Syncer, 2024/11/17
- [nongnu] elpa/emacsql 0d901004b9 4/6: emacsql-sqlite-open: Ensure directory containing database file exists, ELPA Syncer, 2024/11/17
- [nongnu] elpa/emacsql 05b7a25d73 3/6: emacsql-sqlite-open: Add SETUP argument, ELPA Syncer, 2024/11/17
- [nongnu] elpa/emacsql c6e05560be 1/6: emacsql-sqlite-open: Fix typo in doc-string, ELPA Syncer, 2024/11/17
- [nongnu] elpa/emacsql 44b4f89407 2/6: emacsql-sqlite-open: Enable foreign key constrains, ELPA Syncer, 2024/11/17
- [nongnu] elpa/emacsql c8fceaf236 5/6: emacsql-sqlite-connection: New function,
ELPA Syncer <=
- [nongnu] elpa/emacsql 937d45a1c3 6/6: make: Compile emacsql-sqlite.el, ELPA Syncer, 2024/11/17