[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/emacsql 1f57b77c4f 007/427: Add command logging.
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/emacsql 1f57b77c4f 007/427: Add command logging. |
Date: |
Tue, 13 Dec 2022 02:59:23 -0500 (EST) |
branch: elpa/emacsql
commit 1f57b77c4fe67ffbacfbeedb925a3515b6dfd909
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>
Add command logging.
---
emacsql.el | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/emacsql.el b/emacsql.el
index a0e9b6a1c3..8c3d91c9ef 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -58,7 +58,7 @@
"Path to the sqlite3 executable.")
(cl-defstruct (emacsql (:constructor emacsql--create))
- process file)
+ process file log)
(defvar emacsql-connections ()
"Collection of all known emacsql connections.
@@ -77,8 +77,11 @@ This collection exists for cleanup purposes.")
"Retrieve value from REF."
(gethash t ref))
-(defun emacsql-connect (file)
- "Open a connected to database stored in FILE."
+(cl-defun emacsql-connect (file &key log)
+ "Open a connected to database stored in FILE.
+
+:log LOG -- When non-nil, log all SQLite commands to a log
+buffer. This is for debugging purposes."
(emacsql-start-reap-timer)
(let* ((buffer (generate-new-buffer "*emacsql-connection*"))
(process (start-process "emacsql" buffer sqlite-program-name file)))
@@ -86,6 +89,8 @@ This collection exists for cleanup purposes.")
(process-send-string process ".prompt #\n")
(process-send-string process ".mode line\n")
(let ((emacsql (emacsql--create :process process :file file)))
+ (when log
+ (setf (emacsql-log emacsql) (generate-new-buffer "*emacsql-log*")))
(prog1 emacsql
(push (cons (copy-seq emacsql) (emacsql--ref emacsql))
emacsql-connections)))))
@@ -122,9 +127,17 @@ This collection exists for cleanup purposes.")
(cancel-timer emacsql-reap-timer)
(setf emacsql-reap-timer nil)))
+(defun emacsql--log (emacsql &rest messages)
+ (let ((log (emacsql-log emacsql)))
+ (when log
+ (with-current-buffer log
+ (setf (point) (point-max))
+ (mapc (lambda (s) (princ s log)) messages)))))
+
(defun emacsql--send (emacsql string)
"Send STRING to EMACSQL, automatically appending newline."
(let ((process (emacsql-process emacsql)))
+ (emacsql--log emacsql string "\n")
(process-send-string process string)
(process-send-string process "\n")))
- [nongnu] branch elpa/emacsql created (now 6b2e65bdf7), ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 08ea1e6636 005/427: Wrap with single rather than double quotes., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 1f57b77c4f 007/427: Add command logging.,
ELPA Syncer <=
- [nongnu] elpa/emacsql c7597ab813 001/427: Initial commit., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 3b24b5d17c 002/427: Drop closed-p field., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 161e3a41b1 006/427: Add some tests., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 97e9764343 008/427: Change the API of emacsql-insert., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql ccfafd7703 012/427: Always quote non-number values., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 1074113f03 016/427: Add readability note., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 727f3c8566 022/427: Make nil correspond to NULL., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql f8d9511d1d 025/427: Tweak README limitations paragraph., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 2f0a9457a4 029/427: Drop non-idiomatic :else., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 4f6b524b9f 026/427: Rename spec to schema., ELPA Syncer, 2022/12/13