Skip to content

Commit

Permalink
Merge pull request #292 from gh-liu/table_name_sorter
Browse files Browse the repository at this point in the history
feat: table name sort function
  • Loading branch information
kristijanhusak authored Dec 1, 2024
2 parents 28a1690 + 59496f6 commit 7f89265
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion autoload/db_ui/drawer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,12 @@ function! s:drawer.render_tables(tables, db, path, level, schema) abort
if !a:tables.expanded
return
endif
for table in a:tables.list
if type(g:Db_ui_table_name_sorter) ==? type(function('tr'))
let tables_list = call(g:Db_ui_table_name_sorter, [a:tables.list])
else
let tables_list = a:tables.list
endif
for table in tables_list
call self.add(table, 'toggle', a:path.'->'.table, self.get_toggle_icon('table', a:tables.items[table]), a:db.key_name, a:level, { 'expanded': a:tables.items[table].expanded })
if a:tables.items[table].expanded
for [helper_name, helper] in items(a:db.table_helpers)
Expand Down
20 changes: 20 additions & 0 deletions doc/dadbod-ui.txt
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,26 @@ g:Db_ui_buffer_name_generator
let g:Db_ui_buffer_name_generator = function('s:buffer_name_generator')
<

Default value: `0`

*g:Db_ui_table_name_sorter
g:Db_ui_table_name_sorter
Custom function for sorting table names.
Function accepts the table name list and return the sorted
table name list.
Note the uppercase `D`, which is required by vim for
functions.
Also, `make sure that name is always unique` to avoid any issues
with overlapping names.
Example:
>
function s:table_name_sorter(tables)
return sort(tables)
endfunction
let g:Db_ui_table_name_sorter = function('s:table_name_sorter')
<

Default value: `0`

*g:db_ui_default_query*
Expand Down
1 change: 1 addition & 0 deletions plugin/db_ui.vim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ let g:db_ui_execute_on_save = get(g:, 'db_ui_execute_on_save', 1)
let g:db_ui_force_echo_notifications = get(g:, 'db_ui_force_echo_notifications', 0)
let g:db_ui_use_nvim_notify = get(g:, 'db_ui_use_nvim_notify', 0)
let g:Db_ui_buffer_name_generator = get(g:, 'Db_ui_buffer_name_generator', 0)
let g:Db_ui_table_name_sorter = get(g:, 'Db_ui_table_name_sorter', 0)
let g:db_ui_debug = get(g:, 'db_ui_debug', 0)
let g:db_ui_hide_schemas = get(g:, 'db_ui_hide_schemas', [])
let g:db_ui_bind_param_pattern = get(g: , 'db_ui_bind_param_pattern', ':\w\+')
Expand Down

0 comments on commit 7f89265

Please sign in to comment.