nikclayton / ob-sql-mode

sql-mode backend for Org Babel
GNU General Public License v3.0
31 stars 10 forks source link

Configuring ob-sql-mode to use a member of the sql-connection-alist #9

Closed hh closed 8 months ago

hh commented 4 years ago

3 is closed, and #4 is merged, but I'm still unsure how to configure an sql-mode src-block to use a particular sql-connection.

hh commented 4 years ago

Here's a possible work around if there isn't already something obvious that I'm missing.

https://github.com/nikclayton/ob-sql-mode/blob/b31a016585324ad91f1742ff6205bcb76f3ece6e/ob-sql-mode.el#L237-L257

Maybe something like:

(defun org-babel-sql-mode-initiate-session (&optional session _params)
  "Return the comint buffer for this `SESSION'.
Determines the buffer from values in `PARAMS'."
  (let* ((bufname (org-babel-sql-mode--buffer-name _params))
         (sql-bufname (format "*SQL: %s*" bufname))
         (buf (get-buffer sql-bufname))
         (product (intern (cdr (assoc :product _params))))
         ;;; Add connection parameter to src-mode SRC blocks
         (connection (intern (cdr (assoc :connection _params))))
)
;;; currently we call sql-product-interactive with only the product and buffname
              (sql-product-interactive product bufname)
;;; It would be nice to use connection if it's provided and available in sql-connection-alist
              (sql-connect connection bufname)
hh commented 4 years ago

Including folks from #3: /cc @conornash @indigoviolet @stardiviner @nikclayton

mplscorwin commented 10 months ago

Hi there!

Is this still an issue? Reading the code, it seems to me that the change is intended to plug-in to the :session header for src blocks. Have you experimented with this, at all? (I haven't, yet.)

TIA

hobbes commented 8 months ago

just tried right now and it works: just put your sql-connection-alist's entry name in :session and it will take parameters from there.

hh commented 8 months ago

This was my intention, as we wanted to have multiple connections defined and only change the :session.