kristijanhusak / vim-dadbod-ui

Simple UI for https://github.com/tpope/vim-dadbod
MIT License
1.36k stars 70 forks source link

override ui table helpers to execute external command, eg. pg_dump #250

Closed erlangparasu closed 2 weeks ago

kristijanhusak commented 2 weeks ago

You can override table helpers with https://github.com/kristijanhusak/vim-dadbod-ui/blob/master/doc/dadbod-ui.txt#L416, but you cannot run external commands with it. That's out of scope.

erlangparasu commented 2 weeks ago

@kristijanhusak Thanks I currently need to add some function

file: lua/plugins/vim-dadbod-ui.lua

return {
  "kristijanhusak/vim-dadbod-ui",
  cmd = { "DBUI", "DBUIToggle", "DBUIAddConnection", "DBUIFindBuffer" },
  dependencies = "vim-dadbod",
  keys = {
    { "<leader>D", "<cmd>DBUIToggle<CR>", desc = "Toggle DBUI" },
  },
  init = function()
    -- ...

    vim.g.db_ui_table_helpers = {
      postgresql = {
        Count = "SELECT COUNT(*) FROM {optional_schema}{table}",
        Explain = "EXPLAIN ANALYZE {last_query}",
        Definition = "\\d+ {optional_schema}{table}",
      },
    }
  end,
}

It works for me. Thanks!