emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [PATCH] ob-sql.el: Option to reference connections in `sql-connectio


From: Stefano Rodighiero
Subject: [O] [PATCH] ob-sql.el: Option to reference connections in `sql-connection-alist'
Date: Sun, 24 Mar 2019 13:04:33 +0100

Hi,

[This is the first patch I ever submitted.  I hope it complies with
your standards: if it does not, I'll be happy to work on it until it's
fine.  I am not sure it qualifies as a tiny change.]

Org-babel allows SQL snippets to be run on a database connection that
can be specified in the source block header using parameters such as
:dbhost, :dbuser, :dbpassword and so forth.

This is very useful, but I'd also like to be able to use symbolic
references to connections defined elsewhere, so that for example one
does not have to specify the password every time, interactively or,
worse, in the .org file itself.

I am also a user of sql.el, that provides a custom variable
`sql-connection-alist', where users can define a mapping between
connection names and connection details.

The patch I'm submitting extends the behavior of
org-babel-execute:sql so that it's possible to specify a new param
:dbconnection containing a connection name, used for looking up
`sql-connection-alist'.

For example, if `sql-connection-alist' contains something like:

  (("mydb" (sql-product 'postgres)
     (sql-post 5432)
   (sql-server "mydb.server")
   (sql-user "stefano")
   (sql-password "supersecret")))

Then it's possible to use:

  #+begin_src sql :engine postgresql :dbconnection mydb
    select foo, bar, baz from mytable
  #+end_src

s.


--

Attachment: 0001-ob-sql.el-Option-to-reference-connections-in-sql-con.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]