[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/emacsql 6d17256e1b 171/427: Add a mix-in class to reduce c
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/emacsql 6d17256e1b 171/427: Add a mix-in class to reduce code duplication. |
Date: |
Tue, 13 Dec 2022 02:59:39 -0500 (EST) |
branch: elpa/emacsql
commit 6d17256e1b80da18e7bbd69c880cd4f4b9cf1af8
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>
Add a mix-in class to reduce code duplication.
---
emacsql-psql.el | 4 ++--
emacsql-sqlite.el | 23 ++---------------------
emacsql.el | 33 +++++++++++++++++++++++++++++++--
3 files changed, 35 insertions(+), 25 deletions(-)
diff --git a/emacsql-psql.el b/emacsql-psql.el
index 008eb8334c..56583f6de4 100644
--- a/emacsql-psql.el
+++ b/emacsql-psql.el
@@ -26,7 +26,7 @@
nil)))
(error :cannot-execute)))))
-(defclass emacsql-psql-connection (emacsql-connection)
+(defclass emacsql-psql-connection (emacsql-connection emacsql-simple-parser)
((dbname :reader emacsql-psql-dbname :initarg :dbname))
(:documentation "A connection to a PostgreSQL database."))
@@ -91,7 +91,7 @@
(emacsql-clear connection)
(emacsql-send-string connection sql-string)
(emacsql-psql--check-error connection)
- (emacsql-sqlite--parse connection)))
+ (emacsql-simple-parse connection)))
(provide 'emacsql-psql)
diff --git a/emacsql-sqlite.el b/emacsql-sqlite.el
index 6bb1f2e5c1..4708ffbaf2 100644
--- a/emacsql-sqlite.el
+++ b/emacsql-sqlite.el
@@ -26,7 +26,7 @@
nil)))
(error :cannot-execute)))))
-(defclass emacsql-sqlite-connection (emacsql-connection)
+(defclass emacsql-sqlite-connection (emacsql-connection emacsql-simple-parser)
((file :initarg :file
:type (or null string)
:documentation "Database file name."))
@@ -71,25 +71,6 @@ buffer. This is for debugging purposes."
(when (process-live-p process)
(process-send-string process ".exit\n"))))
-(defmethod emacsql-waiting-p ((connection emacsql-sqlite-connection))
- (with-current-buffer (emacsql-buffer connection)
- (cond ((= (buffer-size) 1) (string= "]" (buffer-string)))
- ((> (buffer-size) 1) (string= "\n]"
- (buffer-substring
- (- (point-max) 2) (point-max)))))))
-
-(defun emacsql-sqlite--parse (connection)
- "Parse SQLite output into an s-expression."
- (with-current-buffer (emacsql-buffer connection)
- (let ((standard-input (current-buffer)))
- (setf (point) (point-min))
- (cl-loop until (looking-at "]")
- collect (read) into row
- when (looking-at "\n")
- collect row into rows
- and do (progn (forward-char 1) (setf row ()))
- finally (cl-return rows)))))
-
(defvar emacsql-sqlite-condition-alist
'(("unable to open" emacsql-access)
("cannot open" emacsql-access)
@@ -157,7 +138,7 @@ buffer. This is for debugging purposes."
(emacsql-clear connection)
(emacsql-send-string connection sql-string)
(emacsql-sqlite--check-error connection)
- (emacsql-sqlite--parse connection)))
+ (emacsql-simple-parse connection)))
(provide 'emacsql-sqlite)
diff --git a/emacsql.el b/emacsql.el
index eb30f73ca3..17a574d56d 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -115,7 +115,7 @@ MESSAGE should not have a newline on the end."
"Like `error', but signal an emacsql-syntax condition."
(signal 'emacsql-syntax (list (apply #'format format args))))
-;;; Sending and receiving:
+;; Sending and receiving:
(defmethod emacsql-send-string
((connection emacsql-connection) string &optional no-log)
@@ -140,6 +140,35 @@ MESSAGE should not have a newline on the end."
(not (emacsql-waiting-p connection)))
(accept-process-output (emacsql-process connection) timeout))))
+;; Helper mix-in class:
+
+(defclass emacsql-simple-parser ()
+ ()
+ (:documentation "A mix-in for back-ends with a specific output format.")
+ :abstract t)
+
+(defmethod emacsql-waiting-p ((connection emacsql-simple-parser))
+ "The back-end must us a single \"]\" character as its prompt.
+This prompt value was chosen because it is unreadable."
+ (with-current-buffer (emacsql-buffer connection)
+ (cond ((= (buffer-size) 1) (string= "]" (buffer-string)))
+ ((> (buffer-size) 1) (string= "\n]"
+ (buffer-substring
+ (- (point-max) 2) (point-max)))))))
+
+(defmethod emacsql-simple-parse ((connection emacsql-simple-parser))
+ "Parse output into an s-expression.
+Output should have one row per line, separated by whitespace."
+ (with-current-buffer (emacsql-buffer connection)
+ (let ((standard-input (current-buffer)))
+ (setf (point) (point-min))
+ (cl-loop until (looking-at "]")
+ collect (read) into row
+ when (looking-at "\n")
+ collect row into rows
+ and do (progn (forward-char 1) (setf row ()))
+ finally (cl-return rows)))))
+
(provide 'emacsql) ; end of generic function declarations
;; Automatic connection cleanup:
@@ -218,7 +247,7 @@ A statement can be a list, containing a statement with its
arguments."
else
collect (append (list 'emacsql 'emacsql--conn) statement))))
-;;; Escaping:
+;; Escaping:
(defun emacsql-quote (string)
"Quote STRING for use in a SQL expression."
- [nongnu] elpa/emacsql e597696682 358/427: Fix some indentation (whitespace cleanup), (continued)
- [nongnu] elpa/emacsql e597696682 358/427: Fix some indentation (whitespace cleanup), ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 76489e0a10 362/427: Tweak Makefile documentation, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 8c5f095458 368/427: Bump to version 3.0.0 (#20), ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 49348329df 376/427: Document op. precedence handling, clean up format string expansion, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 50ae54d159 053/427: Use expressions in select columns., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql a13eba5f05 059/427: Use the timeout argument in emacsql-wait., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql d440b44778 076/427: Add escape vector test., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 1db49d7f4c 090/427: Add Windows notice again., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 1ad58cd68d 108/427: Allow substatement in IN operator., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 8fa7c00978 170/427: Add sentinel cleanup to psql., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 6d17256e1b 171/427: Add a mix-in class to reduce code duplication.,
ELPA Syncer <=
- [nongnu] elpa/emacsql 749becb017 181/427: Disable notices and warnings in psql., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql e42d939235 187/427: In SQLite, block for up to 30 seconds on db lock., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 3ba9109d45 198/427: Start using real version numbers., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql de0bde9a02 207/427: Use Cask package-file directive instead., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql bb3dbfc891 213/427: Set a global query timeout., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 394bb062aa 219/427: Add a small library for determining binary to use., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql f030b9952d 224/427: Fix up psql-connection., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql dc2afbbc1f 221/427: Adjust the Emacsql wire protocol., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 6318472b20 223/427: Link the Makefiles together., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql a7728339ba 216/427: Switch to custom middleware., ELPA Syncer, 2022/12/13