跳到主要内容

用 NEOVIM 查询 DB

· 阅读需 1 分钟

你可以点击这里查看最新的配置

涉及到的插件:

  • kristijanhusak/vim-dadbod-ui
  • tpope/vim-dadbod
  • hrsh7th/nvim-cmp
  • kristijanhusak/vim-dadbod-completion

Usecase

我用了这个 Docker Image 起了这个一个 DB https://github.com/ghusta/docker-postgres-world-db

下面是一些连接参数

DB_HOST = "localhost"
DB_PORT = "5432"
DB_NAME = "world-db"
DB_USER = "world"
DB_PASS = "world123"

db-1

完整配置

-- this is a lazy.nvim config
return {
{
"kristijanhusak/vim-dadbod-ui",
dependencies = "tpope/vim-dadbod",
event = "VeryLazy",
},
{
"hrsh7th/nvim-cmp",
optional = true,
dependencies = {
{
"kristijanhusak/vim-dadbod-completion",
event = "VeryLazy",
init = function()
vim.api.nvim_create_autocmd("FileType", {
desc = "dadbod completion",
group = vim.api.nvim_create_augroup("dadbod_cmp", { clear = true }),
pattern = { "sql", "mysql", "plsql" },
callback = function()
require("cmp").setup.buffer({ sources = { { name = "vim-dadbod-completion" } } })
end,
})
end,
},
},
},
}