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

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

[nongnu] elpa/emacsql c634a1b6e1 340/427: Use initialize-instance with e


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql c634a1b6e1 340/427: Use initialize-instance with emacsql-sqlite (fixes #17).
Date: Tue, 13 Dec 2022 03:00:00 -0500 (EST)

branch: elpa/emacsql
commit c634a1b6e106e64c5ee179350f10234ad7dfcec6
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>

    Use initialize-instance with emacsql-sqlite (fixes #17).
    
    This allows classes to properly inherit from emacsql-sqlite-connection,
    since it will configure itself.
---
 emacsql-sqlite.el | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/emacsql-sqlite.el b/emacsql-sqlite.el
index 8e089a865f..b881db114b 100644
--- a/emacsql-sqlite.el
+++ b/emacsql-sqlite.el
@@ -88,31 +88,36 @@ http://www.sqlite.org/lang_keywords.html";)
                       (nil nil))))
   (:documentation "A connection to a SQLite database."))
 
-(cl-defun emacsql-sqlite (file &key debug)
-  "Open a connected to database stored in FILE.
-If FILE is nil use an in-memory database.
-
-:debug LOG -- When non-nil, log all SQLite commands to a log
-buffer. This is for debugging purposes."
+(defmethod initialize-instance :after
+  ((connection emacsql-sqlite-connection) &key)
   (emacsql-sqlite-ensure-binary)
   (let* ((process-connection-type nil)  ; use a pipe
          (coding-system-for-write 'utf-8-auto)
          (coding-system-for-read 'utf-8-auto)
+         (file (slot-value connection 'file))
          (buffer (generate-new-buffer " *emacsql-sqlite*"))
          (fullfile (if file (expand-file-name file) ":memory:"))
          (process (start-process
-                   "emacsql-sqlite" buffer emacsql-sqlite-executable fullfile))
-         (connection (make-instance 'emacsql-sqlite-connection
-                                    :process process
-                                    :file (when file fullfile))))
+                   "emacsql-sqlite" buffer emacsql-sqlite-executable 
fullfile)))
+    (setf (slot-value connection 'process) process)
     (setf (process-sentinel process)
           (lambda (proc _) (kill-buffer (process-buffer proc))))
     (emacsql-wait connection)
     (emacsql connection [:pragma (= busy-timeout $s1)]
              (/ (* emacsql-global-timeout 1000) 2))
-    (when debug (emacsql-enable-debugging connection))
     (emacsql-register connection)))
 
+(cl-defun emacsql-sqlite (file &key debug)
+  "Open a connected to database stored in FILE.
+If FILE is nil use an in-memory database.
+
+:debug LOG -- When non-nil, log all SQLite commands to a log
+buffer. This is for debugging purposes."
+  (let ((connection (make-instance 'emacsql-sqlite-connection :file file)))
+    (when debug
+      (emacsql-enable-debugging connection))
+    connection))
+
 (defmethod emacsql-close ((connection emacsql-sqlite-connection))
   "Gracefully exits the SQLite subprocess."
   (let ((process (emacsql-process connection)))



reply via email to

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