[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/emacsql 578a71d2d8 157/427: Re-order some definitions to g
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/emacsql 578a71d2d8 157/427: Re-order some definitions to group them. |
Date: |
Tue, 13 Dec 2022 02:59:38 -0500 (EST) |
branch: elpa/emacsql
commit 578a71d2d8fca0da023197e1dbd014ca8f1cdaa0
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>
Re-order some definitions to group them.
---
emacsql.el | 72 ++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 39 insertions(+), 33 deletions(-)
diff --git a/emacsql.el b/emacsql.el
index 2196d282ed..abec8f6771 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -61,10 +61,34 @@
(defvar emacsql-sqlite3-executable "sqlite3"
"Path to the sqlite3 executable.")
+(defun emacsql-sqlite3-unavailable-p ()
+ "Return a reason if the sqlite3 executable is not available.
+
+:no-executable -- cannot find the executable
+:cannot-execute -- cannot run the executable
+:old-version -- sqlite3 version is too old"
+ (let ((sqlite3 emacsql-sqlite3-executable))
+ (if (null (executable-find sqlite3))
+ :no-executable
+ (condition-case _
+ (with-temp-buffer
+ (call-process sqlite3 nil (current-buffer) nil "--version")
+ (let ((version (car (split-string (buffer-string)))))
+ (if (version< version "3.7.15")
+ :old-version
+ nil)))
+ (error :cannot-execute)))))
+
+;;; Connection handling:
+
(cl-defstruct (emacsql (:constructor emacsql--create))
"A connection to a SQLite database."
process file log)
+(defun emacsql-buffer (conn)
+ "Get proccess buffer for CONN."
+ (process-buffer (emacsql-process conn)))
+
(defvar emacsql-connections ()
"Collection of all known emacsql connections.
This collection exists for cleanup purposes.")
@@ -90,24 +114,6 @@ This collection exists for cleanup purposes.")
do (accept-process-output)))
(emacsql--clear conn))
-(defun emacsql-sqlite3-unavailable-p ()
- "Return a reason if the sqlite3 executable is not available.
-
-:no-executable -- cannot find the executable
-:cannot-execute -- cannot run the executable
-:old-version -- sqlite3 version is too old"
- (let ((sqlite3 emacsql-sqlite3-executable))
- (if (null (executable-find sqlite3))
- :no-executable
- (condition-case _
- (with-temp-buffer
- (call-process sqlite3 nil (current-buffer) nil "--version")
- (let ((version (car (split-string (buffer-string)))))
- (if (version< version "3.7.15")
- :old-version
- nil)))
- (error :cannot-execute)))))
-
(cl-defun emacsql-connect (file &key log)
"Open a connected to database stored in FILE.
If FILE is nil use an in-memory database.
@@ -163,10 +169,6 @@ A statement can be a list, containing a statement with its
arguments."
else
collect (append (list 'emacsql 'emacsql--conn) statement))))
-(defun emacsql-buffer (conn)
- "Get proccess buffer for CONN."
- (process-buffer (emacsql-process conn)))
-
(defun emacsql-reap ()
"Clean up after lost connections."
(cl-loop for (conn-copy . ref) in emacsql-connections
@@ -189,6 +191,8 @@ A statement can be a list, containing a statement with its
arguments."
(cancel-timer emacsql-reap-timer)
(setf emacsql-reap-timer nil)))
+;;; Sending and receiving:
+
(defun emacsql--log (conn &rest messages)
"Log MESSAGES into CONN's log."
(let ((log (emacsql-log conn)))
@@ -231,6 +235,18 @@ A statement can be a list, containing a statement with its
arguments."
collect row into rows and do (setf row ())
finally (cl-return rows)))))
+(defun emacsql--check-error (conn)
+ "Return non-nil or throw an appropriate error."
+ (with-current-buffer (emacsql-buffer conn)
+ (emacsql-wait conn)
+ (setf (point) (point-min))
+ (prog1 t
+ (when (looking-at "Error:")
+ (error (buffer-substring (line-beginning-position)
+ (line-end-position)))))))
+
+;;; Escaping:
+
(defun emacsql-quote (string)
"Quote STRING for use in a SQL expression."
(format "'%s'" (replace-regexp-in-string "'" "''" string)))
@@ -249,16 +265,6 @@ A statement can be a list, containing a statement with its
arguments."
(replace-regexp-in-string ":" "." string)
string)))
-(defun emacsql--check-error (conn)
- "Return non-nil or throw an appropriate error."
- (with-current-buffer (emacsql-buffer conn)
- (emacsql-wait conn)
- (setf (point) (point-min))
- (prog1 t
- (when (looking-at "Error:")
- (error (buffer-substring (line-beginning-position)
- (line-end-position)))))))
-
(defun emacsql-wait (conn &optional timeout)
"Block Emacs until CONN has finished sending output."
(let ((end (when timeout (+ (float-time) timeout))))
@@ -279,7 +285,7 @@ A statement can be a list, containing a statement with its
arguments."
(list (mapconcat #'emacsql-escape-vector vector ", "))
(vector (concat "(" (mapconcat #'emacsql-escape-value vector ", ") ")"))))
-;; SQL Expansion:
+;; Structured SQL compilation:
(defvar emacsql-expanders ()
"Alist of all expansion functions.")
- [nongnu] elpa/emacsql b2d83c6477 123/427: Fix up ORDER BY, drop :ascending-by., (continued)
- [nongnu] elpa/emacsql b2d83c6477 123/427: Fix up ORDER BY, drop :ascending-by., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql f52af86b05 124/427: Break apart and organize compilation tests., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 0bff8ccc34 126/427: Fix up README., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql a362a97c98 136/427: Add README section on foreign keys., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 223db2d397 141/427: Add quote operator., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 8951084b40 143/427: Add variable escaping., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 19a65f390e 147/427: Add ignored features section to README., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 530b0ad98c 151/427: Allow arbitrary sub-statements., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 3012f5b725 154/427: Fix typo., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 301e2ff4b6 175/427: Drop "simple" from helper method names., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 578a71d2d8 157/427: Re-order some definitions to group them.,
ELPA Syncer <=
- [nongnu] elpa/emacsql 935cca89a9 176/427: Add updated information about Windows., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql b3aea1e6af 055/427: Oops, fix >= back., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql c4396ec5e6 057/427: Fix a bunch of warnings., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql e9fbc4a913 061/427: Fill out a Makefile., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 829298d5a7 063/427: Add dependency listing., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 231ec586ca 088/427: Drop forced process coding system., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql eba26bead6 102/427: Add emacsql-compile function for debugging., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql d5cfaee783 158/427: Be more precise about error messages., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql f512300aba 054/427: Fix a few things in emacsql-expr., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql e900f99091 075/427: Update examples., ELPA Syncer, 2022/12/13