Created
January 6, 2015 22:13
-
-
Save nchapon/f4b3528d62b693b7de1d to your computer and use it in GitHub Desktop.
SQL connect with ido
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Sql specfic config | |
(setq sql-connection-alist | |
'((cnp (sql-product 'mysql) | |
(sql-port 3306) | |
(sql-server "localhost") | |
(sql-user "cnp") | |
;;(sql-password "pwd") | |
(sql-database "cnp")) | |
(speedy (sql-product 'mysql) | |
(sql-port 3307) | |
(sql-server "11.2.1.255") | |
(sql-user "java@%") | |
;;(sql-password "java") | |
(sql-database "speedy_java")))) | |
(setq nc-sql-password | |
'((cnp "pwd") | |
(speedy "java"))) | |
(defun nc/sql-connect () | |
(interactive) | |
(let* ((connection (intern (ido-completing-read "Server :" (mapcar (lambda (item) | |
(symbol-name (nth 0 item))) | |
sql-connection-alist)))) | |
(connection-info (assoc connection sql-connection-alist)) | |
(connection-product (nth 1 (nth 1 (assoc 'sql-product connection-info)))) | |
(sql-password (nth 1 (assoc connection nc-sql-password)))) | |
(setq sql-product connection-product) | |
;; remove | |
(setq sql-connection-alist (assq-delete-all connection sql-connection-alist)) | |
;; delete the old password from the connection-info | |
(setq connection-info (assq-delete-all 'sql-password connection-info)) | |
;; add the password to the connection-info | |
(nconc connection-info `((sql-password ,sql-password))) | |
;; add back the connection info to the beginning of sql-connection-alist | |
;; (last used server will appear first for the next prompt) | |
(add-to-list 'sql-connection-alist connection-info) | |
(sql-connect connection))) | |
(provide 'nc-sql) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment