Permalink
Browse files

Add VDBIDatasouce command to list all datasources.

  • Loading branch information...
1 parent b366309 commit d5f9f21d80d8fd94a022c3912f3d152214c4f268 @heavenshell heavenshell committed Mar 10, 2012
Showing with 77 additions and 11 deletions.
  1. +57 −9 autoload/vdbi.vim
  2. +18 −1 doc/vdbi.txt
  3. +2 −1 plugin/vdbi.vim
View
@@ -333,19 +333,64 @@ function! vdbi#datasource_history(...)
return map(reverse(deepcopy(s:history.datasource)), 'v:val[0]')
endfunction
-function! s:startup_vdbi()
+function! vdbi#show_datasources()
+ if len(s:datasource) > 0
+ call vdbi#shutdown()
+ endif
+
+ if !bufexists('[VDBI:Datasources]')
+ silent botright 5split
+ silent edit `='[VDBI:Datasources]'`
+ setlocal bufhidden=wipe buftype=nofile noswapfile nobuflisted
+ setlocal filetype=vdbi conceallevel=3 concealcursor=nvic
+ setlocal nowrap
+ nnoremap <buffer> <silent> q :bw!<cr>
+ nnoremap <buffer> <silent> <cr> :call <SID>startup_vdbi_from_history()<cr>
+ hi link VdbiHeader Title
+ syntax match VdbiHeader "^\w.*"
+ let datasources = vdbi#datasource_history()
+ for datasource in datasources
+ silent! execute 'normal! O' . datasource
+ endfor
+ silent! execute 'normal! Gddgg'
+ setlocal nomodifiable
+ else
+ call vdbi#tables()
+ endif
+endfunction
+
+function! s:startup_vdbi_from_history()
+ let datasource = getline('.')
+ hide
+ if !s:startup_vdbi(datasource) | return | endif
+ call s:tables()
+endfunction
+
+function! s:startup_vdbi(...)
if len(s:datasource) == 0
- if s:datasource == '' | let s:datasource = input('DataSource: ', '', 'customlist,vdbi#datasource_history') | endif
- if len(s:datasource) == 0 | return 0 | endif
- let i = index(map(deepcopy(s:history.datasource), 'v:val[0]'), s:datasource)
- if i != -1
+ let history_datasource = ''
+ if a:0 > 0
+ let history_datasource = a:1
+ endif
+
+ if history_datasource == ''
+ if s:datasource == '' | let s:datasource = input('DataSource: ', '', 'customlist,vdbi#datasource_history') | endif
+ if len(s:datasource) == 0 | return 0 | endif
+ let i = index(map(deepcopy(s:history.datasource), 'v:val[0]'), s:datasource)
+ if i != -1
+ let username = s:history.datasource[i][1]
+ let password = s:history.datasource[i][2]
+ else
+ let [username, password] = ['', '']
+ endif
+ let username = input('Username: ', username)
+ let password = inputsecret('Password: ', password)
+ else
+ let s:datasource = history_datasource
+ let i = index(map(deepcopy(s:history.datasource), 'v:val[0]'), s:datasource)
let username = s:history.datasource[i][1]
let password = s:history.datasource[i][2]
- else
- let [username, password] = ['', '']
endif
- let username = input('Username: ', username)
- let password = inputsecret('Password: ', password)
try
augroup VDBI
@@ -455,7 +500,10 @@ endfunction
function! vdbi#tables()
if !s:startup_vdbi() | return | endif
+ call s:tables()
+endfunction
+function! s:tables()
call vdbi#clear_view()
call s:message('Listing table infomations...')
View
@@ -21,7 +21,7 @@ ToDo |vdbi-todo|
==============================================================================
INTRODUCTION *vbdi-introduction* *vbdi*
-|VBDI| is vim application which can manipulate database. This plugin works:
+|VBDI| is vim application which can manipulate database. This plugin works:
* view tables
* view columns of the table
@@ -109,5 +109,22 @@ viewer has following key mappings for normal mode.
<leader>e : execute SQL. (also for insert mode)
<leader>r : open history window.
+3. Datasource Viewer *vbdi-datasource-viewer*
+
+Type |:VDBIDatasouce| shows all datasources which is stored in ~/.vdbi_history
+file.
+You can choose datasource and type <cr> to open Table Viewer.
+and password.
+
+>
+ dbi:SQLite:dbname=/path/to/database/foo.db
+ dbi:mysql:database=foo
+ dbi:Pg:dbname=foo
+ dbi:Oracle:foo
+<
+Datasource viewer has following key mapping for normal mode.
+ q : hide window.
+ <cr> : enter Table Viewer.
+
==============================================================================
vim:tw=78:ts=8:ft=help:norl:noet:fen:fdl=0:
View
@@ -1,8 +1,9 @@
" vdbi.vim
-" Last Change: 2012-03-08
+" Last Change: 2012-03-10
" Maintainer: Yasuhiro Matsumoto <mattn.jp@gmail.com>
" License: BSD style license
command! -nargs=0 VDBI call vdbi#tables()
command! -nargs=+ VDBIExec call vdbi#execute(<q-args>)
command! -nargs=0 VDBIReset call vdbi#shutdown()
+command! -nargs=0 VDBIDatasources call vdbi#show_datasources()

0 comments on commit d5f9f21

Please sign in to comment.