This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-09
Channels
- # announcements (3)
- # babashka (17)
- # beginners (75)
- # calva (43)
- # cider (1)
- # clj-kondo (54)
- # cljdoc (8)
- # cljs-dev (70)
- # clojure (83)
- # clojure-europe (27)
- # clojure-nl (4)
- # clojure-norway (4)
- # clojure-spec (8)
- # clojure-uk (13)
- # clojured (2)
- # clojurescript (47)
- # community-development (4)
- # conjure (2)
- # cursive (3)
- # datomic (5)
- # emacs (5)
- # events (3)
- # fulcro (13)
- # graalvm-mobile (19)
- # helix (2)
- # introduce-yourself (1)
- # jobs (2)
- # jobs-discuss (28)
- # kaocha (9)
- # livestream (11)
- # malli (15)
- # meander (24)
- # nextjournal (8)
- # off-topic (26)
- # pathom (1)
- # pedestal (8)
- # polylith (2)
- # portal (31)
- # re-frame (4)
- # reagent (10)
- # reitit (8)
- # remote-jobs (3)
- # sci (1)
- # shadow-cljs (66)
- # spacemacs (20)
- # testing (6)
- # vim (15)
- # xtdb (7)
What is the simple and idiomatic way to configure org-babel languages within spacemacs. I’ve tried
(defun dotspacemacs/user-config ()
(with-eval-after-load 'org
(org-babel-do-load-languages
'org-babel-load-languages
'((sql . t))))
But when I try to execute
#+name: my-query
#+begin_src sql
select * from people
#+end_src
I’m asked to confirm that I’d like to execute the code block, and when I answer yes, I get
Wrong type argument: stringp, nil
I didn't need to add any config for Clojure, although I did need to start a Clojure REPL. https://practical.li/spacemacs/org-mode/literate-programming/
I assume the SQL layer is installed and confirmed working already https://develop.spacemacs.org/layers/+lang/sql/README.html
Actually, I'd not installed the sql layer, as native emacs has basic sql support. But subsequently, I've installed the sql layer and testing now.
Em... So, I've installed the sql layer. I've connected to a database with M-x sql-postgres
and been able to query tables etc. I've also saved the connection. and connected to that saved session. But once again, when I attempt to run a sql command in a orgmode file, I receive the same error.
It's definitely related to my configuration though.
If I remove my attempted babel config, I can successfully execute the following org file section.
#+name: list files
#+begin_src bash
ls
#+end_src
It correctly lists files.However, if I apply my config, then I can't even execute that bash script, and I receive the same Wrong type argument: stringp, nil. error
Oh, that might be a red herring. I didn't realise , b b
prompted and execute every script in the file.
Going to grab some food, and come back to it later. As well as look at the thread in #clojure about configuring Cider to include the :test
profile when running tests so I can pick up test-resources
The Org code block that was provided only defines a names query, to be used with other code blocks, as you discovered it does not run the SQL query.
To run an SQL query, details of the database should be provided in the meta data of the code block, e.g.
#+name: my-query
#+header: :engine mysql
#+header: :dbhost host
#+header: :dbuser user
#+header: :dbpassword pwd
#+header: :database dbname
#+begin_src sql
SELECT * FROM mytable
WHERE id > 500
#+end_src
This is from https://www.orgmode.org/worg/org-contrib/babel/languages/ob-doc-sql.htmlOh, that makes sense although I assumed you could define the connection info elsewhere so I wouldn't, for example, commit them to git?
I also assume you could just define the connection once in the org file and then just use that, but not sure of the syntax.
Okay, cheers. I'll try these later!
I'm interested in how you get on, so feel free to share anything that works. It seems some languages support session-based evaluation. If SQL supports this then perhaps the database information can be shared between code blocks. If SQL doesnt support session-based evaluation, then probably have to include the database connection details for each code block.
Or you could define all the SQL statements as their own named code blocks and use those statements in a language block, such as Clojure, and run those queries using next.jdbc. Not something I have tried yet though.
So declaring the parameters fails a bit later in the process. So, proving general postgres connectivity using M-x postgress
…
db=> select count(*) from locations;
select count(*) from locations;
count
----------
123456789
(1 row)
But valid sql blocks in an org file result in empty result
#+name: my-query
#+header: :engine postgres
#+header: :dbhost redacted
#+header: :dbuser redacted
#+header: :dbpassword redacted
#+header: :database db
#+begin_src sql
SELECT count(*) FROM locations
#+end_src
#+RESULTS: my-query
|---|
and invalid queries (misspelt table name) don’t returns errors, but once again empty results suggesting it doesn’t actually do anything.
#+name: my-query
#+header: :engine postgres
#+header: :dbhost redacted
#+header: :dbuser redacted
#+header: :dbpassword redacted
#+header: :database db
#+begin_src sql
SELECT count(*) FROM incorrect_locations
#+end_src
#+RESULTS: my-query
|---|
Time to put this down, and revert back to using .sql
files, at least for the day.
Sorry to hear it didn't work, thanks for sharing.