[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/emacsql 4db068920d 247/427: Provide MySQL front-end.
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/emacsql 4db068920d 247/427: Provide MySQL front-end. |
Date: |
Tue, 13 Dec 2022 02:59:48 -0500 (EST) |
branch: elpa/emacsql
commit 4db068920d2f2e0b0812e8789ae59f62c4207e97
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>
Provide MySQL front-end.
---
README.md | 2 +-
emacsql-mysql.el | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index d9236aded4..da19b75656 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# Emacsql
Emacsql is a high-level Emacs Lisp front-end for SQLite (primarily),
-PostgreSQL, and potentially other SQL databases.
+PostgreSQL, MySQL, and potentially other SQL databases.
It is currently a work-in-progress (around 90% complete).
diff --git a/emacsql-mysql.el b/emacsql-mysql.el
new file mode 100644
index 0000000000..6f228ba83f
--- /dev/null
+++ b/emacsql-mysql.el
@@ -0,0 +1,71 @@
+;;; emacsql-mysql.el --- front-end for MySQL -*- lexical-binding: t; -*-
+
+;;; Code:
+
+(require 'cl-lib)
+(require 'eieio)
+(require 'emacsql)
+
+(defvar emacsql-mysql-executable "mysql"
+ "Path to the mysql command line executable.")
+
+(defvar emacsql-mysql-sentinel "--------------\n\n--------------\n\n"
+ "What MySQL will print when it has completed its output.")
+
+(defclass emacsql-mysql-connection (emacsql-connection)
+ ((dbname :reader emacsql-psql-dbname :initarg :dbname)
+ (types :allocation :class
+ :reader emacsql-types
+ :initform '((integer "BIGINT")
+ (float "DOUBLE")
+ (object "LONGTEXT")
+ (nil "LONGTEXT")))))
+
+(defun emacsql-mysql (dbname)
+ (let* ((buffer (generate-new-buffer " *emacsql-mysql*"))
+ (mysql emacsql-mysql-executable)
+ (process (start-process "emacsql-mysql" buffer mysql
+ "-rfBNL" "--skip-pager" dbname))
+ (connection (make-instance 'emacsql-mysql-connection
+ :process process
+ :dbname dbname)))
+ (setf (process-sentinel process)
+ (lambda (proc _) (kill-buffer (process-buffer proc))))
+ (emacsql-register connection)))
+
+(defmethod emacsql-close ((connection emacsql-mysql-connection))
+ (let ((process (emacsql-process connection)))
+ (when (process-live-p process)
+ (process-send-eof process))))
+
+(defmethod emacsql-send-message ((connection emacsql-mysql-connection) message)
+ (let ((process (emacsql-process connection)))
+ (process-send-string process message)
+ (process-send-string process "\\c\\p\n")))
+
+(defmethod emacsql-waiting-p ((connection emacsql-mysql-connection))
+ (let ((length (length emacsql-mysql-sentinel)))
+ (with-current-buffer (emacsql-buffer connection)
+ (and (>= (buffer-size) length)
+ (progn (setf (point) (- (point-max) length))
+ (looking-at emacsql-mysql-sentinel))))))
+
+(defmethod emacsql-parse ((connection emacsql-mysql-connection))
+ (with-current-buffer (emacsql-buffer connection)
+ (let ((standard-input (current-buffer)))
+ (setf (point) (point-min))
+ (when (looking-at "ERROR")
+ (let ((beg (line-beginning-position))
+ (end (line-end-position)))
+ (signal 'emacsql-error (list (buffer-substring beg end)))))
+ (cl-loop until (looking-at emacsql-mysql-sentinel)
+ collect (read) into row
+ when (looking-at "\n")
+ collect row into rows
+ and do (setf row ())
+ and do (forward-char)
+ finally (cl-return rows)))))
+
+(provide 'emacsql-mysql)
+
+;;; emacsql-mysql.el ends here
- [nongnu] elpa/emacsql dc2afbbc1f 221/427: Adjust the Emacsql wire protocol., (continued)
- [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
- [nongnu] elpa/emacsql ab53199d07 232/427: Fix escaping issue in middleware., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 6ad267f93b 229/427: Change :value to :scalar., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 1146f2e26a 233/427: Flesh out the changes in the README., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql ed77eac846 237/427: Add string prepared statements., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 847196cafa 226/427: Set tty to raw in psql., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 3e5ce21b0d 242/427: Tweak the new implementation notes., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql a459708684 244/427: Move tests into their own directory., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 4db068920d 247/427: Provide MySQL front-end.,
ELPA Syncer <=
- [nongnu] elpa/emacsql dce6736e04 249/427: Oops, add new MySQL module to the Makefile., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql fcba876d0e 251/427: Solve the tty (pty) issue in MySQL., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql fb0e2d5423 256/427: Fix typecase typo., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql a6e859f1b5 260/427: Normalize darwin OS., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 4332bd67ec 271/427: Flesh out the main header a bit more., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 4e9297233d 273/427: Don't rely on C99 mode., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 7963261ef3 270/427: Bump to version 1.0.0., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 6f6533ab70 272/427: Add Cygwin note., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 45f43323ad 275/427: Check the compiler error code., ELPA Syncer, 2022/12/13
- [nongnu] elpa/emacsql 2f606fdd2d 300/427: Fix with-transaction macro to return results., ELPA Syncer, 2022/12/13