Skip to content

Commit 6e548cc

Browse files

File tree

1 file changed

+5
-62
lines changed

1 file changed

+5
-62
lines changed

paw-db.el

Lines changed: 5 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33

44
(require 'emacsql)
5+
;; REVIEW: is this require needed?
6+
;; emacsql-sqlite provides a common interface to an emacsql SQLite backend (e.g. emacs-sqlite-builtin)
7+
;; not to be confused with a backend itself named emacsql-sqlite that existed in emacsql < 4.0.
8+
(require 'emacsql-sqlite)
59
(require 'dash)
610

711
(defcustom paw-db-file
@@ -10,42 +14,6 @@
1014
:group 'paw
1115
:type 'file)
1216

13-
(defcustom paw-db-connector (if (and (progn
14-
(require 'emacsql-sqlite-builtin nil t)
15-
(functionp 'emacsql-sqlite-builtin))
16-
(functionp 'sqlite-open))
17-
'sqlite-builtin
18-
'sqlite)
19-
"The database connector used by paw.
20-
This must be set before `paw' is loaded. To use an alternative
21-
connector you must install the respective package explicitly.
22-
The default is `sqlite', which uses the `emacsql-sqlite' library
23-
that is being maintained in the same repository as `emacsql'
24-
itself.
25-
If you are using Emacs 29, then the recommended connector is
26-
`sqlite-builtin', which uses the new builtin support for SQLite.
27-
You need to install the `emacsql-sqlite-builtin' package to use
28-
this connector.
29-
If you are using an older Emacs release, then the recommended
30-
connector is `sqlite-module', which uses the module provided by
31-
the `sqlite3' package. This is very similar to the previous
32-
connector and the built-in support in Emacs 29 derives from this
33-
module. You need to install the `emacsql-sqlite-module' package
34-
to use this connector.
35-
For the time being `libsqlite3' is still supported. Do not use
36-
this, it is an older version of the `sqlite-module' connector
37-
from before the connector and the package were renamed.
38-
For the time being `sqlite3' is also supported. Do not use this.
39-
This uses the third-party `emacsql-sqlite3' package, which uses
40-
the official `sqlite3' cli tool, which is not intended
41-
to be used like this. See https://nullprogram.com/blog/2014/02/06/."
42-
:group 'wallabag
43-
:type '(choice (const sqlite)
44-
(const sqlite-builtin)
45-
(const sqlite-module)
46-
(const :tag "libsqlite3 (OBSOLETE)" libsqlite3)
47-
(const :tag "sqlite3 (BROKEN)" sqlite3)))
48-
4917

5018
(defvar paw-db-connection nil
5119
"The EmacSQL database connection.")
@@ -55,31 +23,6 @@ to be used like this. See https://nullprogram.com/blog/2014/02/06/."
5523
(defvar paw-db-newp nil)
5624
(defvar paw-db-update-p nil)
5725

58-
(defun paw-db--conn-fn ()
59-
"Return the function for creating the database connection."
60-
(cl-case paw-db-connector
61-
(sqlite
62-
(progn
63-
(require 'emacsql-sqlite)
64-
#'emacsql-sqlite))
65-
(sqlite-builtin
66-
(progn
67-
(require 'emacsql-sqlite-builtin)
68-
#'emacsql-sqlite-builtin))
69-
(sqlite-module
70-
(progn
71-
(require 'emacsql-sqlite-module)
72-
#'emacsql-sqlite-module))
73-
(libsqlite3
74-
(progn
75-
(require 'emacsql-libsqlite3)
76-
#'emacsql-libsqlite3))
77-
(sqlite3
78-
(progn
79-
(require 'emacsql-sqlite3)
80-
#'emacsql-sqlite3))))
81-
82-
8326
(defun paw-db ()
8427
"Connect or create database.
8528
serverp:
@@ -95,7 +38,7 @@ serverp:
9538
(unless (and paw-db-connection (emacsql-live-p paw-db-connection))
9639
(unless (file-exists-p (concat user-emacs-directory ".cache/"))
9740
(make-directory (concat user-emacs-directory ".cache/")))
98-
(setq paw-db-connection (funcall (paw-db--conn-fn) paw-db-file))
41+
(setq paw-db-connection (emacsql-sqlite-open paw-db-file))
9942

10043
;; create items table
10144
(emacsql paw-db-connection [:create-table :if-not-exists items ([(word STRING :primary-key)

0 commit comments

Comments
 (0)