[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/emacsql 649fc6b0b4 312/427: Add emacsql-pg using pg.el as
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/emacsql 649fc6b0b4 312/427: Add emacsql-pg using pg.el as a back-end. |
Date: |
Tue, 13 Dec 2022 02:59:54 -0500 (EST) |
branch: elpa/emacsql
commit 649fc6b0b4164456e36c9cdd099a03d4a97212ae
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>
Add emacsql-pg using pg.el as a back-end.
---
Makefile | 2 +-
emacsql-pg.el | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
emacsql-psql.el | 2 +-
emacsql.el | 2 +-
4 files changed, 73 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
index 90f49dbcf9..58e39ff9b6 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ PACKAGE := emacsql
VERSION := $(shell $(CASK) version)
EL = emacsql-compiler.el emacsql-system.el emacsql.el \
- emacsql-sqlite.el emacsql-psql.el emacsql-mysql.el
+ emacsql-sqlite.el emacsql-psql.el emacsql-mysql.el emacsql-pg.el
ELC = $(EL:.el=.elc)
EXTRA_DIST = README.md UNLICENSE
diff --git a/emacsql-pg.el b/emacsql-pg.el
new file mode 100644
index 0000000000..80508249db
--- /dev/null
+++ b/emacsql-pg.el
@@ -0,0 +1,70 @@
+;;; emacsql-pg.el --- PostgreSQL (pg.el) back-end -*- lexical-binding: t; -*-
+
+;;; Commentary:
+
+;; Unlike emacsql-psql, this connection type uses Eric Marsden's pg.el
+;; to connect to PostgreSQL. It speaks directly to the database, so
+;; unlike the other EmacSQL connection types, this one requires no
+;; external command line programs.
+
+;; The only pg functions required are pg:connect, pg:disconnect,
+;; pg:exec, and pg:result. Unfortunately, since pg.el is synchronous
+;; it will not be fully compliant once EmacSQL supports asynchronous
+;; queries. But, on the plus side, this means the implementation below
+;; is dead simple.
+
+;;; Code:
+
+(require 'pg)
+(require 'eieio)
+(require 'cl-lib)
+(require 'emacsql)
+(require 'emacsql-psql) ; for reserved words
+
+(defclass emacsql-pg-connection (emacsql-connection)
+ ((pgcon :reader emacsql-pg-pgcon :initarg :pgcon)
+ (dbname :reader emacsql-pg-dbname :initarg :dbname)
+ (result :accessor emacsql-pg-result)
+ (types :allocation :class
+ :reader emacsql-types
+ :initform '((integer "BIGINT")
+ (float "DOUBLE PRECISION")
+ (object "TEXT")
+ (nil "TEXT"))))
+ (:documentation "A connection to a PostgreSQL database via pg.el."))
+
+(cl-defun emacsql-pg (dbname user &key
+ (host "localhost") (password "") (port 5432)
debug)
+ "Connect to a PostgreSQL server using pg.el."
+ (let* ((pgcon (pg:connect dbname user password host port))
+ (connection (make-instance 'emacsql-pg-connection
+ :process (pgcon-process pgcon)
+ :pgcon pgcon
+ :dbname dbname)))
+ (when debug (emacsql-enable-debugging connection))
+ (emacsql connection [:set (= default-transaction-isolation 'SERIALIZABLE)])
+ (emacsql-register connection)))
+
+(defmethod emacsql-close ((connection emacsql-pg-connection))
+ (ignore-errors (pg:disconnect (emacsql-pg-pgcon connection))))
+
+(defmethod emacsql-send-message ((connection emacsql-pg-connection) message)
+ (condition-case error
+ (setf (emacsql-pg-result connection)
+ (pg:exec (emacsql-pg-pgcon connection) message))
+ (error (signal 'emacsql-error error))))
+
+(defmethod emacsql-waiting-p ((_connection emacsql-pg-connection))
+ ;; pg:exec will block
+ t)
+
+(defmethod emacsql-parse ((connection emacsql-pg-connection))
+ (let ((tuples (pg:result (emacsql-pg-result connection) :tuples)))
+ (cl-loop for tuple in tuples collect
+ (cl-loop for value in tuple
+ when (stringp value) collect (read value)
+ else collect value))))
+
+(provide 'emacsql-pg)
+
+;;; emacsql-pg.el ends here
diff --git a/emacsql-psql.el b/emacsql-psql.el
index 86df1e355e..26ce9067df 100644
--- a/emacsql-psql.el
+++ b/emacsql-psql.el
@@ -49,7 +49,7 @@
http://www.postgresql.org/docs/7.3/static/sql-keywords-appendix.html")
(float "DOUBLE PRECISION")
(object "TEXT")
(nil "TEXT"))))
- (:documentation "A connection to a PostgreSQL database."))
+ (:documentation "A connection to a PostgreSQL database via psql."))
(cl-defun emacsql-psql (dbname &key username hostname port debug)
"Connect to a PostgreSQL server using the psql command line program."
diff --git a/emacsql.el b/emacsql.el
index 5a86a53eed..bc8f07f5e5 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -5,7 +5,7 @@
;; Author: Christopher Wellons <wellons@nullprogram.com>
;; URL: https://github.com/skeeto/emacsql
;; Version: 1.0.2
-;; Package-Requires: ((emacs "24.3") (cl-lib "0.3") (finalize "1.0.0"))
+;; Package-Requires: ((emacs "24.3") (cl-lib "0.3") (finalize "1.0.0") (pg
"0.12"))
;;; Commentary:
- [nongnu] elpa/emacsql cfde8bea56 291/427: Update README for new customization variable., (continued)
- [nongnu] elpa/emacsql cfde8bea56 291/427: Update README for new customization variable., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 46850a75d0 268/427: Update the README., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 3e6a24e22a 303/427: Escape identifiers that collide with keywords., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql c4036cbdc8 280/427: Move test print statement., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 1bf92bab9e 285/427: Add a special case for unary not., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql da2b137771 289/427: Fix the parameter naming in emacsql-show-last-sql., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql c1ede49bbe 283/427: Update headers., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 965039cec2 314/427: Adjust header lines for each back-end., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 57c40202e8 307/427: Set correct default transaction type in PostgreSQL., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 7b505b6e94 309/427: Update back-end documentation., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 649fc6b0b4 312/427: Add emacsql-pg using pg.el as a back-end.,
ELPA Syncer <=
- [nongnu] elpa/emacsql 4a535e2cca 318/427: Fix typo in emacsql-buffer's doc-string, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql a5a0c2f838 323/427: Fix typo, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql e6ce8ded45 326/427: Require url when running emacsql-sqlite-download, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 01f3d3eb2b 316/427: Fallback to buffer-file-name when load-file-name is nil, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 02acd07072 328/427: Ensure executable variable is defined at compile time., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 2ffcc95c67 338/427: Fix a typo in the doc-string of emacsql-with-params., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 74bd11bc09 334/427: Fix up package description headers., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 5df2891557 349/427: Use cl-generic package, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql e8c090e11f 353/427: Improve Makefile portability and dump Cask, ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 0ba12b89d5 084/427: Drop "work in progress.", ELPA Syncer, 2022/12/13