Navigation Menu

Skip to content

Commit

Permalink
Add options and toggles for showing duration and curl cmd
Browse files Browse the repository at this point in the history
Option and toggle for showing duration for query, defaults to show
duration
Option and Toggle for showing curl cmd used for query, defaults to off
because the output has a "--" in it that technically isn't allowed in
xml
Minor other changes
  • Loading branch information
coledarr committed Oct 2, 2012
1 parent 414c50b commit 85b1190
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions plugin/vim-xqmarklogic.vim
Expand Up @@ -22,19 +22,45 @@
" would be to fix the xquery output) For large responses this can be slow
"
" TODO The user and password are encoded in this file, and should be changed
" (prompt for password and cache for later calls)
" (prompt for password and cache for later calls) Or at least allow setting
" the values
" TODO Consider a different script instead of xq.xqy. Use XCC, RestFUL
" interface (MarkLogic6 and later), or even just package up the xq.xqy
" TODO xq.xqy hardcodes database, but it would be better to be configurable
" (db http header can be set to override hardcoded default). Best would be
" configured on a per buffer basis and maybe a default set in .vimrc
" TODO add a real help doc
"
" Maintainer: Darren Cole <http://github.com/coledarr/vim-xqmarklogic>
" Version: 0.1
" Version: 0.3

map <Leader>B :XQ<cr>

command -buffer XQ :execute s:QueryMarkLogic(expand("%"))
" Options
let s:curlCmd=0
let s:showDuration=1

" Toggle Options
command -buffer XQtoggleCurlCmdAppend :execute s:toggleCurlCmdAppend()
function! s:toggleCurlCmdAppend()
if (s:curlCmd)
let s:curlCmd=0
else
let s:curlCmd=1
endif
endfunction
command -buffer XQToggleShowDuration :execute s:toggleShowDuration()
function! s:toggleShowDuration()
if (s:showDuration)
let s:showDuration=0
else
let s:showDuration=1
endif
endfunction

" Running the Query
map <Leader>B :XQmlquery<cr>
command -buffer XQmlquery :execute s:QueryMarkLogic(expand("%"))

let s:host = "localhost"
let s:uri = "http://"
Expand All @@ -44,8 +70,7 @@ let s:password = "password"
let s:xq = "/xq.xqy"

" Used for preview window
let s:out = tempname()

"let s:out = tempname()
function! s:QueryMarkLogic(fname)
" Use preview window
"pedit s:out
Expand All @@ -56,8 +81,18 @@ function! s:QueryMarkLogic(fname)
setlocal buftype=nofile
setlocal filetype=xml

if (s:curlCmd)
call append(0, '<!-- curl --digest --user ' . s:user . ':XXXXXX -s -X PUT -d@"' . a:fname . '" ' . s:uri . s:host . ':' . s:port . s:xq . ' -->')
endif

let start=reltime()
execute 'r! curl --digest --user ' . s:user . ':' . s:password . ' -s -X PUT -d@"' . a:fname . '" ' . s:uri . s:host . ':' . s:port . s:xq
"execut 'r! curl --digest --user admin:password -s -X PUT -d@"' . a:fname . '" http://localhost:8002/xq.xqy'
if (s:showDuration)
let end=reltimestr(reltime(start))
call append(0, '<!-- query_duration="' . end .'" -->')
endif


silent! :%s/></></g
normal gg=G
Expand Down

0 comments on commit 85b1190

Please sign in to comment.