Maksym Prokopov personal blog
Idea is a something worth sharing

Emacs literate programming and SQL

09.01.2021

Reading time: 1 min.

I’m really crying of how finally emacs can be used for the literate programming and for some testing.

For restclient, this creates POST request with json data structure in request body.

  #+begin_src restclient
    POST http://muster.test/index.php?cl=ping
    Content-Type: application/json


    {
    "essentialtech": true,
    "googleadwords": false,
    "googleanalytics": false,
    "googlemaps": true,
    "gtmbasedtech": false,
    "terminland": true,
    "userlike": true
    }
#+end_src

#+RESULTS:
#+BEGIN_SRC js
{
  "message": "success"
}
// POST http://muster.test/index.php?cl=ping
// HTTP/1.1 200 OK
// Date: Tue, 09 Feb 2021 13:45:07 GMT
// Server: Apache/2.4.46 (Unix) OpenSSL/1.1.1i
// X-Powered-By: PHP/7.1.33
// Expires: Thu, 19 Nov 1981 08:52:00 GMT
// Cache-Control: no-store, no-cache, must-revalidate
// Pragma: no-cache
// Set-Cookie: language=0; path=/; HttpOnly
// Set-Cookie: sid=0fvjai2h5h2pso52p4vq9e5309; path=/; HttpOnly
// Keep-Alive: timeout=5, max=100
// Connection: Keep-Alive
// Transfer-Encoding: chunked
// Content-Type: application/json;
// Request duration: 0.269261s
#+END_SRC

This executes SQL statement and checks what the previous command has been executed!

#+begin_src  sql :engine mysql :dbhost 127.0.0.1 :dbuser muster :dbpassword muster :database muster-development
select val, attribute, count(*)
from oxps_user_consent_pings 
where attribute='googleanalytics' and time > '2021-01-01'
group by val
#+end_src

#+RESULTS:
| val   | attribute       | count(*) |
|-------|-----------------|----------|
| false | googleanalytics |        2 |
| true  | googleanalytics |        2 |