sparql-mode
sparql-mode copied to clipboard
Allow sparql-execute-query to return simple list from select
The current sparql-execute-query
always inserts query results into the current buffer. Could we have an option to return the results as a simple elisp list instead, so it can be bound to a variable, &c?
As a sketch: run the query with json
result format in a temporary buffer (hopefully to handle multiline string values); apply json-parse-string
to (buffer-string)
; transform into a simple list as return value.
The final RESULTS
in the org-babel example below shows what I'd like to have directly from the query.
#+name: mysmall
#+begin_src sparql :url http://localhost:3030/bfo-core/query
select * {?x ?y ?z} limit 2
#+end_src
#+RESULTS:
| x | y | z |
|----------------+------------+------------------------|
| dc:contributor | rdf:type | owl:AnnotationProperty |
| dc:contributor | rdfs:label | contributor |
#+begin_src emacs-lisp :var result=mysmall() :results code :colnames no
result
#+end_src
#+RESULTS:
#+begin_src emacs-lisp
(("x" "y" "z")
("dc:contributor" "rdf:type" "owl:AnnotationProperty")
("dc:contributor" "rdfs:label" "contributor"))
#+end_src
PS. The main point here is to get the query results as a return value, rather than always inserted into the current buffer.