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

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

[nongnu] elpa/emacsql 7c533fb6c2 3/3: Rename "process" slot to "handle"


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql 7c533fb6c2 3/3: Rename "process" slot to "handle" and make emacsql-process obsolete
Date: Fri, 24 Feb 2023 07:59:04 -0500 (EST)

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

    Rename "process" slot to "handle" and make emacsql-process obsolete
    
    This slot was named "process" when all connector classes used a
    subprocess to communicate with their databases.  Using a process is
    fragile, which is the reason why `emacsql-sqlite-builtin-connection'
    and `emacsql-sqlite-module-connection' were created.
    
    The slot was not renamed because it was only intended for internal use
    anyway, and renaming it comes with the risk of breaking packages that
    accessed it directly anyway.
    
    But to avoid confusion, rename it to `handle' now.  Also document what
    types its value may have and that it is only intended for internal
    use.  Make the `emacsql-process' accessor function obsolete, and forgo
    providing a renamed substitute, to avoid advertising direct access to
    the slot.  For a limited time only, continue to allow direct access to
    the internal slot under its obsolete name, but make noise about it.
    
    Closes #112.
---
 emacsql-mysql.el          |  6 +++---
 emacsql-pg.el             |  4 ++--
 emacsql-psql.el           |  6 +++---
 emacsql-sqlite-builtin.el | 10 +++++-----
 emacsql-sqlite-module.el  | 10 +++++-----
 emacsql-sqlite.el         |  6 +++---
 emacsql.el                | 40 +++++++++++++++++++++++++++++++++-------
 7 files changed, 54 insertions(+), 28 deletions(-)

diff --git a/emacsql-mysql.el b/emacsql-mysql.el
index cf09e996df..ec620678a3 100644
--- a/emacsql-mysql.el
+++ b/emacsql-mysql.el
@@ -85,7 +85,7 @@ http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html";)
            (process (start-process-shell-command
                      "emacsql-mysql" buffer (concat "stty raw &&" command)))
            (connection (make-instance 'emacsql-mysql-connection
-                                      :process process
+                                      :handle process
                                       :dbname database)))
       (set-process-sentinel process
                             (lambda (proc _) (kill-buffer (process-buffer 
proc))))
@@ -97,12 +97,12 @@ http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html";)
       (emacsql-register connection))))
 
 (cl-defmethod emacsql-close ((connection emacsql-mysql-connection))
-  (let ((process (emacsql-process connection)))
+  (let ((process (oref connection handle)))
     (when (process-live-p process)
       (process-send-eof process))))
 
 (cl-defmethod emacsql-send-message ((connection emacsql-mysql-connection) 
message)
-  (let ((process (emacsql-process connection)))
+  (let ((process (oref connection handle)))
     (process-send-string process message)
     (process-send-string process "\\c\\p\n")))
 
diff --git a/emacsql-pg.el b/emacsql-pg.el
index 0a4e7da74a..b1e82de475 100644
--- a/emacsql-pg.el
+++ b/emacsql-pg.el
@@ -47,8 +47,8 @@
   (require 'pg)
   (let* ((pgcon (pg-connect dbname user password host port))
          (connection (make-instance 'emacsql-pg-connection
-                                    :process (and (fboundp 'pgcon-process)
-                                                  (pgcon-process pgcon))
+                                    :handle (and (fboundp 'pgcon-process)
+                                                 (pgcon-process pgcon))
                                     :pgcon pgcon
                                     :dbname dbname)))
     (when debug (emacsql-enable-debugging connection))
diff --git a/emacsql-psql.el b/emacsql-psql.el
index 23e419b286..0d5ab673f5 100644
--- a/emacsql-psql.el
+++ b/emacsql-psql.el
@@ -84,7 +84,7 @@ 
http://www.postgresql.org/docs/7.3/static/sql-keywords-appendix.html";)
            (process (start-process-shell-command
                      "emacsql-psql" buffer (concat "stty raw && " command)))
            (connection (make-instance 'emacsql-psql-connection
-                                      :process process
+                                      :handle process
                                       :dbname dbname)))
       (setf (process-sentinel process)
             (lambda (proc _) (kill-buffer (process-buffer proc))))
@@ -104,12 +104,12 @@ 
http://www.postgresql.org/docs/7.3/static/sql-keywords-appendix.html";)
       (emacsql-register connection))))
 
 (cl-defmethod emacsql-close ((connection emacsql-psql-connection))
-  (let ((process (emacsql-process connection)))
+  (let ((process (oref connection handle)))
     (when (process-live-p process)
       (process-send-string process "\\q\n"))))
 
 (cl-defmethod emacsql-send-message ((connection emacsql-psql-connection) 
message)
-  (let ((process (emacsql-process connection)))
+  (let ((process (oref connection handle)))
     (process-send-string process message)
     (process-send-string process "\n")))
 
diff --git a/emacsql-sqlite-builtin.el b/emacsql-sqlite-builtin.el
index 69fe989af0..cab7585d07 100644
--- a/emacsql-sqlite-builtin.el
+++ b/emacsql-sqlite-builtin.el
@@ -31,7 +31,7 @@
 
 (cl-defmethod initialize-instance :after
   ((connection emacsql-sqlite-builtin-connection) &rest _)
-  (setf (emacsql-process connection)
+  (oset connection handle
         (sqlite-open (slot-value connection 'file)))
   (when emacsql-global-timeout
     (emacsql connection [:pragma (= busy-timeout $s1)]
@@ -52,11 +52,11 @@ buffer. This is for debugging purposes."
     connection))
 
 (cl-defmethod emacsql-live-p ((connection emacsql-sqlite-builtin-connection))
-  (and (emacsql-process connection) t))
+  (and (oref connection handle) t))
 
 (cl-defmethod emacsql-close ((connection emacsql-sqlite-builtin-connection))
-  (sqlite-close (emacsql-process connection))
-  (setf (emacsql-process connection) nil))
+  (sqlite-close (oref connection handle))
+  (oset connection handle nil))
 
 (cl-defmethod emacsql-send-message
   ((connection emacsql-sqlite-builtin-connection) message)
@@ -68,7 +68,7 @@ buffer. This is for debugging purposes."
                                 ((numberp col) col)
                                 (t (read col))))
                         row))
-              (sqlite-select (emacsql-process connection) message nil nil))
+              (sqlite-select (oref connection handle) message nil nil))
     ((sqlite-error sqlite-locked-error)
      (if (stringp (cdr err))
          (signal 'emacsql-error (list (cdr err)))
diff --git a/emacsql-sqlite-module.el b/emacsql-sqlite-module.el
index ae72f284ad..8f8585078c 100644
--- a/emacsql-sqlite-module.el
+++ b/emacsql-sqlite-module.el
@@ -33,7 +33,7 @@
 
 (cl-defmethod initialize-instance :after
   ((connection emacsql-sqlite-module-connection) &rest _)
-  (setf (emacsql-process connection)
+  (oset connection handle
         (sqlite3-open (or (slot-value connection 'file) ":memory:")
                       sqlite-open-readwrite
                       sqlite-open-create))
@@ -56,17 +56,17 @@ buffer. This is for debugging purposes."
     connection))
 
 (cl-defmethod emacsql-live-p ((connection emacsql-sqlite-module-connection))
-  (and (emacsql-process connection) t))
+  (and (oref connection handle) t))
 
 (cl-defmethod emacsql-close ((connection emacsql-sqlite-module-connection))
-  (sqlite3-close (emacsql-process connection))
-  (setf (emacsql-process connection) nil))
+  (sqlite3-close (oref connection handle))
+  (oset connection handle nil))
 
 (cl-defmethod emacsql-send-message
   ((connection emacsql-sqlite-module-connection) message)
   (condition-case err
       (let (rows)
-        (sqlite3-exec (emacsql-process connection)
+        (sqlite3-exec (oref connection handle)
                       message
                       (lambda (_ row __)
                         (push (mapcar (lambda (col)
diff --git a/emacsql-sqlite.el b/emacsql-sqlite.el
index 0f3d176b37..2de14c263c 100644
--- a/emacsql-sqlite.el
+++ b/emacsql-sqlite.el
@@ -71,7 +71,7 @@ used.")
          (fullfile (if file (expand-file-name file) ":memory:"))
          (process (start-process
                    "emacsql-sqlite" buffer emacsql-sqlite-executable 
fullfile)))
-    (setf (slot-value connection 'process) process)
+    (oset connection handle process)
     (set-process-sentinel process
                           (lambda (proc _) (kill-buffer (process-buffer 
proc))))
     (when (memq (process-status process) '(exit signal))
@@ -94,12 +94,12 @@ buffer. This is for debugging purposes."
 
 (cl-defmethod emacsql-close ((connection emacsql-sqlite-connection))
   "Gracefully exits the SQLite subprocess."
-  (let ((process (emacsql-process connection)))
+  (let ((process (oref connection handle)))
     (when (process-live-p process)
       (process-send-eof process))))
 
 (cl-defmethod emacsql-send-message ((connection emacsql-sqlite-connection) 
message)
-  (let ((process (emacsql-process connection)))
+  (let ((process (oref connection handle)))
     (process-send-string process (format "%d " (string-bytes message)))
     (process-send-string process message)
     (process-send-string process "\n")))
diff --git a/emacsql.el b/emacsql.el
index 7f8cce9e0d..bcb48e9961 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -86,8 +86,11 @@ If nil, wait forever.")
 ;;; Database connection
 
 (defclass emacsql-connection ()
-  ((process :initarg :process
-            :accessor emacsql-process)
+  ((handle :initarg :handle
+           :documentation "Internal connection handler.
+The value is a record-like object and should not be accessed
+directly.  Depending on the concrete implementation, `type-of'
+may return `process', `user-ptr' or `sqlite' for this value.")
    (log-buffer :type (or null buffer)
                :initarg :log-buffer
                :initform nil
@@ -109,7 +112,7 @@ If nil, wait forever.")
 
 (cl-defmethod emacsql-live-p ((connection emacsql-connection))
   "Return non-nil if CONNECTION is still alive and ready."
-  (not (null (process-live-p (emacsql-process connection)))))
+  (not (null (process-live-p (oref connection handle)))))
 
 (cl-defgeneric emacsql-types (connection)
   "Return an alist mapping EmacSQL types to database types.
@@ -120,7 +123,7 @@ SQL expression.")
 
 (cl-defmethod emacsql-buffer ((connection emacsql-connection))
   "Get process buffer for CONNECTION."
-  (process-buffer (emacsql-process connection)))
+  (process-buffer (oref connection handle)))
 
 (cl-defmethod emacsql-enable-debugging ((connection emacsql-connection))
   "Enable debugging on CONNECTION."
@@ -139,6 +142,29 @@ MESSAGE should not have a newline on the end."
         (goto-char (point-max))
         (princ (concat message "\n") buffer)))))
 
+(cl-defgeneric emacsql-process (this)
+  "Access internal `handle' slot directly, which you shouldn't do.
+Using this function to do it anyway, means additionally using a
+misnamed and obsolete accessor function."
+  (and (slot-boundp this 'handle)
+       (eieio-oref this 'handle)))
+(cl-defmethod (setf emacsql-process) (value (this emacsql-connection))
+  (eieio-oset this 'handle value))
+(make-obsolete 'emacsql-process "underlying slot is for internal use only."
+               "Emacsql 4.0.0")
+
+(cl-defmethod slot-missing ((connection emacsql-connection)
+                            slot-name operation &optional new-value)
+  "Treat removed `process' slot-name as an alias for internal `handle' slot."
+  (pcase (list operation slot-name)
+    ('(oref process)
+     (message "EmacSQL: Slot `process' is obsolete")
+     (oref connection handle))
+    ('(oset process)
+     (message "EmacSQL: Slot `process' is obsolete")
+     (oset connection handle new-value))
+    (_ (cl-call-next-method))))
+
 ;;; Sending and receiving
 
 (cl-defgeneric emacsql-send-message (connection message)
@@ -149,7 +175,7 @@ MESSAGE should not have a newline on the end."
   (emacsql-log connection message))
 
 (cl-defmethod emacsql-clear ((connection emacsql-connection))
-  "Clear the process buffer for CONNECTION-SPEC."
+  "Clear the connection buffer for CONNECTION-SPEC."
   (let ((buffer (emacsql-buffer connection)))
     (when (and buffer (buffer-live-p buffer))
       (with-current-buffer buffer
@@ -165,7 +191,7 @@ MESSAGE should not have a newline on the end."
     (while (and (or (null real-timeout) (< (float-time) end))
                 (not (emacsql-waiting-p connection)))
       (save-match-data
-        (accept-process-output (emacsql-process connection) real-timeout)))
+        (accept-process-output (oref connection handle) real-timeout)))
     (unless (emacsql-waiting-p connection)
       (signal 'emacsql-timeout (list "Query timed out" real-timeout)))))
 
@@ -200,7 +226,7 @@ must display as \"nil\"."
 
 (cl-defmethod emacsql-waiting-p ((connection emacsql-protocol-mixin))
   "Return t if the end of the buffer has a properly-formatted prompt.
-Also return t if the process buffer has been killed."
+Also return t if the connection buffer has been killed."
   (let ((buffer (emacsql-buffer connection)))
     (or (not (buffer-live-p buffer))
         (with-current-buffer buffer



reply via email to

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