{"id":10256,"date":"2022-01-15T13:56:00","date_gmt":"2022-01-15T18:56:00","guid":{"rendered":"https:\/\/irreal.org\/blog\/?p=10256"},"modified":"2022-01-15T13:56:00","modified_gmt":"2022-01-15T18:56:00","slug":"source-block-executors","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=10256","title":{"rendered":"Source Block Executors"},"content":{"rendered":"<p>Isa Mert Gurbuz (isamert) has a very interesting post on <a href=\"https:\/\/isamert.net\/2022\/01\/04\/dealing-with-apis-jsons-and-databases-in-org-mode.html\">using Org Babel to interactively deal with Web APIs<\/a>. Starting with Zweifisch\u2019s <a href=\"https:\/\/github.com\/zweifisch\/ob-http\">ob-http<\/a>, he queries a site and gets some JSON returned. The ob-http code even allows you to pipe the results through the <a href=\"https:\/\/stedolan.github.io\/jq\/\">jq<\/a> binary to slice and filter the JSON results.<\/p>\n<p>That\u2019s pretty neat but what\u2019s better is he shows us how to make the JSON results \u201cexecutable\u201d. It\u2019s probably not clear what it means to \u201cexecute\u201d JSON but the idea is simple: use can specify source block header parameters to specify filtering or other manipulation. The code to do this is simple and isamert gives an example of such code.<br \/>\nThere are several examples in his post so take a look to see how it all works.<\/p>\n<p>But wait! There\u2019s more. JSON is an existing Emacs major mode but it\u2019s possible to extend the idea to custom modes as well. The example isamert uses is for the <a href=\"https:\/\/www.couchbase.com\/\">Couchbase<\/a> database. There\u2019s no mode for Couchbase, so isamert created one by simply extending <code>sql-mode<\/code>. Then he wrote a function to take an SQL statement and send it to the Couchbase server. Again, that\u2019s simple because Couchbase provides a command line tool. Finally, he wrote an executor for the Couchbase source block thereby providing an interactive Org-mode based tool to manipulate the database. Here\u2019s an example of the its use (n1ql is the name of the mode):<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-org\"><span style=\"color: #b22222;\">#+begin_src n1ql :host DB_HOST :username DB_USERNAME :password DB_PASSWORD<\/span>\n  SELECT * FROM SomeTable LIMIT 10;\n<span style=\"color: #b22222;\">#+end_src<\/span>\n<\/pre>\n<\/div>\n<p>When he executes this block, the database is queried with the SELECT statement and the results are returned in a <code>#+RESULTS:<\/code> block as usual.<\/p>\n<p>This is good stuff and has application outside of Web APIs so it\u2019s well worth spending some time to read and understand isamert\u2019s post even if you don\u2019t routinely deal with Web APIs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Isa Mert Gurbuz (isamert) has a very interesting post on using Org Babel to interactively deal with Web APIs. Starting with Zweifisch\u2019s ob-http, he queries a site and gets some JSON returned. The ob-http code even allows you to pipe &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=10256\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[18,4],"class_list":["post-10256","post","type-post","status-publish","format-standard","hentry","category-general","tag-emacs","tag-org-mode"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10256"}],"version-history":[{"count":1,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10256\/revisions"}],"predecessor-version":[{"id":10257,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10256\/revisions\/10257"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}