Skip to main content

Sql

info

You can enable the extra with the :LazyExtras command. Plugins marked as optional will only be configured if they are installed.

Options

Additional options for this extra can be configured in your lua/config/options.lua file:

lua/config/options.lua
-- The setup below will automatically configure connections without the need for manual input each time.

-- Example configuration using dictionary with keys:
-- vim.g.dbs = {
-- dev = "Replace with your database connection URL.",
-- staging = "Replace with your database connection URL.",
-- }
-- or
-- Example configuration using a list of dictionaries:
-- vim.g.dbs = {
-- { name = "dev", url = "Replace with your database connection URL." },
-- { name = "staging", url = "Replace with your database connection URL." },
-- }

-- or
-- Create a `.lazy.lua` file in your project and set your connections like this:
-- ```lua
-- vim.g.dbs = {...}
--
-- return {}
-- ```

-- Alternatively, you can also use other methods to inject your environment variables.

-- Finally, please make sure to add `.lazy.lua` to your `.gitignore` file to protect your secrets.

Below you can find a list of included plugins and their default settings.

caution

You don't need to copy the default settings to your config. They are only shown here for reference.

vim-dadbod

opts = nil

vim-dadbod-completion

opts = nil

vim-dadbod-ui

opts = nil

vim-dadbod-completion

opts = nil

mason.nvim

Linters & formatters

opts = { ensure_installed = { "sqlfluff" } }

nvim-treesitter (optional)

Treesitter

opts = { ensure_installed = { "sql" } }

edgy.nvim (optional)

Edgy integration

opts = function(_, opts)
opts.right = opts.right or {}
table.insert(opts.right, {
title = "Database",
ft = "dbui",
pinned = true,
width = 0.3,
open = function()
vim.cmd("DBUI")
end,
})

opts.bottom = opts.bottom or {}
table.insert(opts.bottom, {
title = "DB Query Result",
ft = "dbout",
})
end

blink.cmp (optional)

blink.cmp integration

opts = {
sources = {
default = { "dadbod" },
providers = {
dadbod = { name = "Dadbod", module = "vim_dadbod_completion.blink" },
},
},
}

nvim-lint (optional)

opts = function(_, opts)
for _, ft in ipairs(sql_ft) do
opts.linters_by_ft[ft] = opts.linters_by_ft[ft] or {}
table.insert(opts.linters_by_ft[ft], "sqlfluff")
end
end

conform.nvim (optional)

opts = function(_, opts)
opts.formatters.sqlfluff = {
args = { "format", "--dialect=ansi", "-" },
}
for _, ft in ipairs(sql_ft) do
opts.formatters_by_ft[ft] = opts.formatters_by_ft[ft] or {}
table.insert(opts.formatters_by_ft[ft], "sqlfluff")
end
end