Skip to content

Commit

Permalink
Support for alternative connectors
Browse files Browse the repository at this point in the history
The `closql-database' class is abstract now, making it necessary to
define a class that derives from that and also from a connector class.
The choice of which connector to use can be left to the user.  It may
be necessary to define a `closql-db' method for alternative connectors
and possibly other methods as well.

  (cl-case forge-database-connector
    (sqlite
     (defclass forge-database (emacsql-sqlite-connection closql-database)
       ((object-class :initform 'forge-repository))))
    (libsqlite3
     (require (quote emacsql-libsqlite3))
     (with-no-warnings
       (defclass forge-database (emacsql-libsqlite3-connection closql-database)
         ((object-class :initform 'forge-repository))))))
  • Loading branch information
tarsius committed Sep 27, 2021
1 parent e6b0b31 commit cd7c239
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# -*- mode: org -*-
* v1.1.0 2021/09/27

- Added support for alternative database connectors.
The ~closql-database~ class is abstract now, making it necessary to
define a class that derives from that and also from a connector
class.

* v1.0.6 2021/06/16

- Adjusted to how unbound slots are represented in Emacs 28.
Expand Down
8 changes: 5 additions & 3 deletions closql.el
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,9 @@

;;; Database

(defclass closql-database (emacsql-sqlite-connection)
((object-class :allocation :class)))
(defclass closql-database ()
((object-class :allocation :class))
:abstract t)

(cl-defmethod closql-db ((class (subclass closql-database))
&optional variable file debug)
Expand All @@ -283,7 +284,8 @@
(prog1 db (emacsql db [:pragma (= foreign-keys on)]))))
(let ((db-init (not (and file (file-exists-p file))))
(db (make-instance class :file file)))
(set-process-query-on-exit-flag (oref db process) nil)
(when (slot-boundp db 'process)
(set-process-query-on-exit-flag (oref db process) nil))
(when debug
(emacsql-enable-debugging db))
(emacsql db [:pragma (= foreign-keys on)])
Expand Down

0 comments on commit cd7c239

Please sign in to comment.