# HG changeset patch # User Luka Sitas # Date 1790951992 14400 # Node ID 3aa33ab9a907110744bb21475550525031ac2419 # Parent c19add1b66a9391c19315a73831c12b1c67ee2eb tags diff -r c19add1b66a9 -r 3aa33ab9a907 autoload/dbtables.vim --- a/autoload/dbtables.vim Wed Mar 11 12:03:31 2026 -0400 +++ b/autoload/dbtables.vim Fri Oct 02 10:39:52 2026 -0400 @@ -11,8 +11,8 @@ " Utilities "============================================= -let s:query_history = [] -let s:snippets = [] +let g:query_history = [] +let g:snippets = [] @@ -21,23 +21,23 @@ " - - - - - - - - - - - - - - - - - - - - - - " Execute shell commands -function! s:ExecuteShellCommand(command) +function! dbtables#ExecuteShellCommand(command) let result = system(a:command . ' 2>&1') return [v:shell_error == 0, result] endfunction " Execute a SQL query, directly to the db -function! s:ExecuteDBQuery(query) +function! dbtables#ExecuteDBQuery(query) let command = printf('mariadb --user=%s --password=%s --database=%s --host=%s -e %s', \ shellescape(g:db_user), shellescape(g:db_password), \ shellescape(g:db_name), shellescape(g:db_host), \ shellescape(a:query)) - let [success, result] = s:ExecuteShellCommand(command) + let [success, result] = dbtables#ExecuteShellCommand(command) if success return split(result, "\n") else - call s:HandleDBError(result, command) + call dbtables#HandleDBError(result, command) return [] endif endfunction @@ -45,7 +45,7 @@ " Function to execute SQL from the current buffer with parameter prompt function! dbtables#ExecuteSQLQuery() let query = join(getline(1, '$'), "\n") - call s:PromptAndExecuteQuery(query) + call dbtables#PromptAndExecuteQuery(query) endfunction " Function to execute SQL from a visual selection with parameter prompt @@ -55,11 +55,11 @@ let query = join(lines, "\n") " Execute query with prompt for parameters - call s:PromptAndExecuteQuery(query) + call dbtables#PromptAndExecuteQuery(query) endfunction " Handle parameter prompts and execute query -function! s:PromptAndExecuteQuery(query) +function! dbtables#PromptAndExecuteQuery(query) " Identify parameters in the form of :parameter_name let pattern = ':\(\k\+\)' let params = [] @@ -89,12 +89,12 @@ let updated_query = substitute(updated_query, param, value, 'g') endfor - call add(s:query_history, updated_query) - call s:OpenInNewTab('SQLQueryResult', s:ExecuteDBQuery(updated_query)) + call add(g:query_history, updated_query) + call dbtables#OpenInNewTab('SQLQueryResult', dbtables#ExecuteDBQuery(updated_query)) endfunction " Handle database command errors -function! s:HandleDBError(result, command) +function! dbtables#HandleDBError(result, command) echoerr 'Shell command failed: ' . a:command if a:result =~# 'Access denied' echoerr 'Authentication error: Check your username and password.' @@ -116,7 +116,7 @@ " - - - - - - - - - - - - - - - - - - - - - - " Display data in a new read only buffer -function! s:OpenInNewTab(title, data) +function! dbtables#OpenInNewTab(title, data) tabnew enew execute 'file ' . a:title @@ -142,56 +142,56 @@ execute '34 vsplit' enew file DBTables - let tables = s:ExecuteDBQuery("SHOW TABLES;") + let tables = dbtables#ExecuteDBQuery("SHOW TABLES;") if empty(tables) echo "No tables found or an error occurred." else - call append(0, ['Available Tables:'] + tables[1:]) + call append(0, ['Available Tabledbtables#'] + tables[1:]) setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile \ nomodifiable nonumber norelativenumber winfixwidth - nnoremap :call ShowTablePopup() + nnoremap :call dbtables#ShowTablePopup() endif endfunction " Open the database schema -function! s:OpenTableSchema(table) - call s:OpenInNewTab(a:table . '_schema', s:ExecuteDBQuery('DESCRIBE ' . a:table . ';')) +function! dbtables#OpenTableSchema(table) + call dbtables#OpenInNewTab(a:table . '_schema', dbtables#ExecuteDBQuery('DESCRIBE ' . a:table . ';')) endfunction " Open the table data -function! s:OpenTableData(table) - call s:OpenInNewTab(a:table, s:ExecuteDBQuery('SELECT * FROM ' . a:table . ';')) +function! dbtables#OpenTableData(table) + call dbtables#OpenInNewTab(a:table, dbtables#ExecuteDBQuery('SELECT * FROM ' . a:table . ';')) endfunction let s:popup_table = "" " Popup selection for table actions -function! s:ShowTablePopup() +function! dbtables#ShowTablePopup() " Use Vim popup_menu if available if exists('*popup_menu') let s:popup_table = getline(line('.')) let items = ['View Data', 'View Schema', 'Cancel'] call popup_menu(items, #{ - \ callback: 'HandlePopupSelection', + \ callback: 'dbtables#HandlePopupSelection', \ }) return endif " Popup_menu not available echoerr 'Floating popup requires Vim8.2+.' - call s:ShowTableMenuModal() + call dbtables#ShowTableMenuModal() endfunction -function! s:HandlePopupSelection(id, result) +function! dbtables#HandlePopupSelection(id, result) let table = s:popup_table - call s:ClosePopup() + call dbtables#ClosePopup() if a:result == 1 - call s:OpenTableData(table) + call dbtables#OpenTableData(table) elseif a:result == 2 - call s:OpenTableSchema(table) + call dbtables#OpenTableSchema(table) endif endfunction -function! s:ClosePopup() +function! dbtables#ClosePopup() unlet! s:popup_table endfunction @@ -208,9 +208,9 @@ " Open the query history in a new split window execute 'vsplit' enew - call setline(1, s:query_history) - nnoremap :call s:OpenInNewTab('SQLQueryResult', - \ s:ExecuteDBQuery(getline(line('.')))) + call setline(1, g:query_history) + nnoremap :call dbtables#OpenInNewTab('SQLQueryResult', + \ dbtables#ExecuteDBQuery(getline(line('.')))) setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile wrap endfunction @@ -230,12 +230,11 @@ enew " Populate the buffer with the list of snippet files - let s:snippets = globpath(g:snippets_directory, '*', 0, 1) - let l:display = mapnew(s:snippets, 'fnamemodify(v:val, ":t:r")') + let g:snippets = globpath(g:snippets_directory, '*', 0, 1) + let l:display = mapnew(g:snippets, 'fnamemodify(v:val, ":t:r")') call setline(1, l:display) - nnoremap :call s:OpenInNewTab(line('.'), - \ fnameescape(s:snippets[a:lnum-1])) + nnoremap :execute "tabe " . fnameescape(g:snippets[line('.')-1]) setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile wrap endfunction diff -r c19add1b66a9 -r 3aa33ab9a907 doc/tags --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/tags Fri Oct 02 10:39:52 2026 -0400 @@ -0,0 +1,19 @@ +:DBConsole dbtables.txt /*:DBConsole* +:DBTables dbtables.txt /*:DBTables* +:ExecuteSQL dbtables.txt /*:ExecuteSQL* +:QueryHistory dbtables.txt /*:QueryHistory* +:QuerySnippets dbtables.txt /*:QuerySnippets* +dbtables dbtables.txt /*dbtables* +dbtables dbtables.txt /*dbtables* +dbtables-commands dbtables.txt /*dbtables-commands* +dbtables-config dbtables.txt /*dbtables-config* +dbtables-install dbtables.txt /*dbtables-install* +dbtables-mappings dbtables.txt /*dbtables-mappings* +dbtables-notes dbtables.txt /*dbtables-notes* +dbtables-usage dbtables.txt /*dbtables-usage* +dbtables.txt dbtables.txt /*dbtables.txt* +g:db_host dbtables.txt /*g:db_host* +g:db_name dbtables.txt /*g:db_name* +g:db_password dbtables.txt /*g:db_password* +g:db_user dbtables.txt /*g:db_user* +g:snippets_directory dbtables.txt /*g:snippets_directory* diff -r c19add1b66a9 -r 3aa33ab9a907 plugin/dbtables.vim --- a/plugin/dbtables.vim Wed Mar 11 12:03:31 2026 -0400 +++ b/plugin/dbtables.vim Fri Oct 02 10:39:52 2026 -0400 @@ -31,6 +31,6 @@ nnoremap eq :ExecuteSQL xnoremap ev :call dbtables#ExecuteVisualSQLQuery() -nnoremap db :call :DBConsole -nnoremap qh :call :QueryHistory -nnoremap qs :call :QuerySnippets +nnoremap db :DBConsole +nnoremap qh :QueryHistory +nnoremap qs :QuerySnippets