Skip to content

Feature request: command-line options for jq adapter #199

@titaniumtraveler

Description

@titaniumtraveler

Motivation

When writing jq queries it is sometimes necessary to configure some command-line
options for that connection. (In my case specifically --slurp)

Possible Solution

A possible solution would be to allow using the query parameter of the
connection for configuring these.

As an example how that could be done I patched the jq adapter to at least
support ?slurp=true to enable --slurp.
(It is not especially good code and the final interface to set those options
should probably be something better than just ?slurp=true, but it was what
enough to get done what I needed in the moment)

diff --git a/autoload/db/adapter/jq.vim b/autoload/db/adapter/jq.vim
index ffee3df..25c3904 100644
--- a/autoload/db/adapter/jq.vim
+++ b/autoload/db/adapter/jq.vim
@@ -11,16 +11,24 @@ function! db#adapter#jq#output_extension(...) abort
 endfunction
 
 function! s:path_args(url) abort
-  let input = db#url#file_path(a:url)
-  if input =~# '^[\/]\=$'
-    return ['--null-input']
+  let url = db#url#parse(a:url)
+
+  let args = []
+  if get(url.params, "slurp") ==? "true"
+    let args += ["--slurp"]
+  endif
+
+  if empty(url.opaque)
+    return args + ['--null-input']
   else
-    return ['--', input]
+    let args += ['--', url.opaque]
+    return args
   endif
 endfunction
 
 function! db#adapter#jq#input(url, in) abort
-  return ['jq', '--from-file', a:in] + s:path_args(a:url)
+  let args = ['jq', '--from-file', a:in] + s:path_args(a:url)
+  return args
 endfunction
 
 function! db#adapter#jq#auth_input() abort

The patch is on top of the current master. (9f0ca8b)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions