[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/drupal-mode 5ad113d48f 255/308: Add `drupal-drush-sql-cli`
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/drupal-mode 5ad113d48f 255/308: Add `drupal-drush-sql-cli` command |
Date: |
Tue, 25 Jan 2022 10:59:52 -0500 (EST) |
branch: elpa/drupal-mode
commit 5ad113d48f611eb3dded50406a62f72fd9bfda4f
Author: joddie <jonxfield@gmail.com>
Commit: joddie <jonxfield@gmail.com>
Add `drupal-drush-sql-cli` command
---
drupal-mode.el | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 52 insertions(+), 1 deletion(-)
diff --git a/drupal-mode.el b/drupal-mode.el
index f6c9476da6..70e22a9a1d 100644
--- a/drupal-mode.el
+++ b/drupal-mode.el
@@ -36,6 +36,8 @@
(require 'cl)
(require 'php-mode)
(require 'format-spec)
+(require 'json)
+(require 'sql)
;; Silence byte compiler.
(defvar css-indent-level)
@@ -239,7 +241,8 @@ get better filling in Doxygen comments."
(?f . drupal-insert-function)
(?m . drupal-module-name)
(?e . drupal-drush-php-eval)
- (?t . drupal-wrap-string-in-t-function))
+ (?t . drupal-wrap-string-in-t-function)
+ (?s . drupal-drush-sql-cli))
"Map of mnemonic keys and functions for keyboard shortcuts.
See `drupal-mode-map'.")
@@ -428,6 +431,10 @@ of the project)."
[menu-bar drupal cache-clear]
'(menu-item "Clear all caches" drupal-drush-cache-clear
:enable (and drupal-rootdir drupal-drush-program)))
+(define-key drupal-mode-map
+ [menu-bar drupal sql-cli]
+ '(menu-item "Open SQL shell" drupal-drush-sql-cli
+ :enable (and drupal-rootdir drupal-drush-program)))
(define-key drupal-mode-map
[menu-bar drupal drupal-project drupal-project-bugs]
@@ -519,6 +526,50 @@ buffer."
(search-forward-regexp "\\(\"\\|'\\)")
(insert ")")))))
+(defun drupal-drush-sql-cli ()
+ "Run a SQL shell using \"drush sql-cli\" in a SQL-mode comint buffer."
+ (interactive)
+ (require 'sql)
+ (require 'json)
+ (let* ((json-object-type 'plist)
+ (config
+ (json-read-from-string
+ (with-temp-buffer
+ (call-process drupal-drush-program nil t nil
+ "sql-conf" "--format=json")
+ (buffer-string)))))
+ (when (not config)
+ (error "No Drupal SQL configuration found."))
+ (destructuring-bind (&key database driver &allow-other-keys) config
+ (let ((sql-interactive-product
+ (drupal--db-driver-to-sql-product driver))
+ (start-buffer (current-buffer))
+ (sqli-buffer
+ (make-comint (format "SQL (%s)" database)
+ drupal-drush-program nil "sql-cli")))
+ (with-current-buffer sqli-buffer
+ (sql-interactive-mode)
+ (set (make-local-variable 'sql-buffer)
+ (buffer-name (current-buffer)))
+
+ ;; Set `sql-buffer' in the start buffer
+ (with-current-buffer start-buffer
+ (when (derived-mode-p 'sql-mode)
+ (setq sql-buffer (buffer-name sqli-buffer))
+ (run-hooks 'sql-set-sqli-hook)))
+
+ ;; All done.
+ (run-hooks 'sql-login-hook)
+ (pop-to-buffer sqli-buffer))))))
+
+(defun drupal--db-driver-to-sql-product (driver)
+ "Translate a Drupal DB driver name into a sql-mode symbol."
+ (let ((driver (intern driver)))
+ (cond
+ ((eq driver 'pgsql) 'postgres)
+ ((assq driver sql-product-alist) driver)
+ (t 'ansi))))
+
(defvar drupal-form-id-history nil
- [nongnu] elpa/drupal-mode e803c00379 220/308: Only use our phpcs special checker on non PHP-files., (continued)
- [nongnu] elpa/drupal-mode e803c00379 220/308: Only use our phpcs special checker on non PHP-files., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 9a6d3623b9 237/308: User error if the hook is already inserted elsewhere., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode d9e2137a54 229/308: Use `auto-revert-mode` and auto-load., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode accf63bac1 234/308: Made blacklist a configurable regexp., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 945ddcca95 239/308: Implemented async cache clear., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 319acd5761 240/308: Moved eldoc stuff to separate file., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode d09cdf8781 236/308: User error if the hook is already inserted in the file., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 4bd52836b3 238/308: Inherit drupal-style from php style., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 2e51a209df 223/308: Properly concat phpcs option in newer flycheck., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 914d2df539 222/308: Fixed URL of Drupalcontrib.org API., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 5ad113d48f 255/308: Add `drupal-drush-sql-cli` command,
ELPA Syncer <=
- [nongnu] elpa/drupal-mode b62d89c177 251/308: Fix up for latest flycheck., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode c2d7bc42e3 252/308: Merge pull request #63 from arnested/feature/flycheck-update, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 59bbaaf4f1 249/308: Merge branch 'release/0.6.1' into develop, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 0cd2412756 257/308: Avoid "no tags containing" error in hook skeleton, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 36ea4003da 259/308: Merge pull request #65 from joddie/feature/sql-cli, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 2cca689e26 268/308: Better gtags-helm support., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode a02e1dde00 271/308: Merge pull request #72 from arnested/fix-phpcs-output-parsing, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode f425ba445a 276/308: Merge branch 'release/0.7.1' into develop, ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode eec2e557d7 277/308: Updated to the latest flycheck., ELPA Syncer, 2022/01/25
- [nongnu] elpa/drupal-mode 643c7538b0 279/308: Merge pull request #78 from arnested/continuation-style, ELPA Syncer, 2022/01/25