I can connect manually by doing:
M-x sql-postgres
and type the User, Database, Host, Server
I'd like to do something like:
(connect-foo (user "me")(database "bar")(host "earth"))
Solution so far:
I grabbed some code from sql.el and changed it so I can use it non-interactively.
(defun sql-create-buffer (profile)
"derived from sql-product-interactive in sql.el which is"
"covered by GNU General Public License version 3."
(setq sql-user (cdr (assoc 'user profile))
sql-password (cdr (assoc 'password profile))
sql-server (cdr (assoc 'server profile))
sql-database (cdr (assoc 'database profile)))
(setq product 'postgres) ;;(cdr (assoc 'product profile)))
(when (sql-product-feature :sqli-connect product)
(if (comint-check-proc "*SQL*")
(pop-to-buffer "*SQL*")
;; Connect to database.
(message "Login...")
(funcall (sql-product-feature :sqli-connect product))
;; Set SQLi mode.
(setq sql-interactive-product product)
(setq sql-buffer (current-buffer))
(sql-interactive-mode)
;; All done.
(message "Login...done")
(pop-to-buffer sql-buffer))))
(setq bar-profile '(
(product . "postgres")
(user . "me")
(password . "")
(server . "earth")
(database . "bar")))
I don't know what to do with the 'product' parameter, so I left it hard coded for now. It is 'postgres in sql.el.
(sql-create-buffer bar-profile)