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

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

[nongnu] elpa/emacsql 70e95655df 8/9: emacsql-sqlite-default-connection:


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql 70e95655df 8/9: emacsql-sqlite-default-connection: New function
Date: Wed, 22 Feb 2023 14:59:08 -0500 (EST)

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

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

diff --git a/emacsql-sqlite-common.el b/emacsql-sqlite-common.el
index 4226ccaa91..378df3e6d5 100644
--- a/emacsql-sqlite-common.el
+++ b/emacsql-sqlite-common.el
@@ -85,6 +85,31 @@ ERRSTR).  Also see https://www.sqlite.org/rescode.html.";)
 
 ;;; Utilities
 
+(defun emacsql-sqlite-default-connection ()
+  "Determine and return the best SQLite connection class.
+If a module or binary is required and that doesn't exist yet,
+then try to compile it.  Signal an error if no connection class
+can be used."
+  (or (and (fboundp 'sqlite-available-p)
+           (sqlite-available-p)
+           (require 'emacsql-sqlite-builtin)
+           'emacsql-sqlite-builtin-connection)
+      (and (boundp 'module-file-suffix)
+           module-file-suffix
+           (and (with-demoted-errors
+                    "Cannot use `emacsql-sqlite-module-connection': %S"
+                  (require 'emacsql-sqlite-module))
+                'emacsql-sqlite-module-connection))
+      (and (require 'emacsql-sqlite)
+           (boundp 'emacsql-sqlite-executable)
+           (or (file-exists-p emacsql-sqlite-executable)
+               (with-demoted-errors
+                   "Cannot use `emacsql-sqlite-connection': %S"
+                 (and (fboundp 'emacsql-sqlite-compile)
+                      (emacsql-sqlite-compile 2))))
+           'emacsql-sqlite-connection)
+      (error "EmacSQL could not find or compile a back-end")))
+
 (defun emacsql-sqlite-list-tables (connection)
   "Return a list of the names of all tables in CONNECTION.
 Tables whose names begin with \"sqlite_\", are not included



reply via email to

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