Skip to content

Commit 58fc776

Browse files
Carlos Alvarezsigz
andauthored
Add Explain command and partial selection query execution (#9)
* Allows to run a selected text inside a full query * Add explain command shortcuts Co-authored-by: sigz <[email protected]>
1 parent 284fce1 commit 58fc776

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

plugin/vim-mysql-plugin.vim

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fun! g:RunArray(sqlarray, timing)
4747
endif
4848

4949
if a:timing
50-
let l:thesql = ['SELECT NOW(3)+0 INTO @startTime;'] + a:sqlarray + ['SELECT CONCAT(ROUND(NOW(3) - @startTime, 3), "s") Took']
50+
let l:thesql = ['SELECT NOW(3)+0 INTO @startTime;'] + a:sqlarray + ['; SELECT CONCAT(ROUND(NOW(3) - @startTime, 3), "s") Took']
5151
else
5252
let l:thesql = a:sqlarray
5353
endif
@@ -72,13 +72,27 @@ func! g:DescriptCursorTable()
7272
call RunArray(['SHOW FULL COLUMNS FROM `' . l:Table . '`;'], 0)
7373
endfun
7474

75-
fun! g:RunInstruction()
75+
fun! s:GetInstruction()
7676
let l:PrevSemicolon = search(';', 'bnW')
7777
let l:NextSemicolon = search(';', 'nW')
78-
let l:Lines = getline(l:PrevSemicolon, l:NextSemicolon)[1:]
78+
return getline(l:PrevSemicolon, l:NextSemicolon)[1:]
79+
endfun
80+
81+
fun! g:RunInstruction()
82+
let l:Lines = s:GetInstruction()
7983
call g:RunArray(l:Lines, 1)
8084
endfun
8185

86+
fun! g:RunExplain()
87+
let l:Lines = s:GetInstruction()
88+
call g:RunArray(['explain '] + l:Lines, 1)
89+
endfun
90+
91+
fun! g:RunExplainSelection()
92+
let l:Selection = g:GetSelection()
93+
call g:RunArray(['explain '] + l:Selection, 1)
94+
endfun
95+
8296
fun! s:GetCommand()
8397
let l:Command = 'mysql '
8498
let l:LineNum = 1
@@ -97,3 +111,5 @@ autocmd FileType sql nnoremap <silent><buffer> <leader>ss :call g:SelectCursorTa
97111
autocmd FileType sql nnoremap <silent><buffer> <leader>ds :call g:DescriptCursorTable()<CR>
98112
autocmd FileType sql nnoremap <silent><buffer> <leader>rs :call g:RunSelection()<CR>
99113
autocmd FileType sql vnoremap <silent><buffer> <leader>rs :<C-U>call g:RunSelection()<CR>
114+
autocmd FileType sql nnoremap <silent><buffer> <leader>re :call g:RunExplain()<CR>
115+
autocmd FileType sql vnoremap <silent><buffer> <leader>re :call g:RunExplainSelection()<CR>

0 commit comments

Comments
 (0)