feat: adding new database
This commit is contained in:
115
lua/cargdev/core/keymaps/database.lua
Normal file
115
lua/cargdev/core/keymaps/database.lua
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
-- =============================================================================
|
||||||
|
-- DATABASE KEYMAPS
|
||||||
|
-- =============================================================================
|
||||||
|
|
||||||
|
local keymap = vim.keymap
|
||||||
|
local opts = { noremap = true, silent = true }
|
||||||
|
|
||||||
|
-- =============================================================================
|
||||||
|
-- GLOBAL DATABASE KEYMAPS
|
||||||
|
-- =============================================================================
|
||||||
|
|
||||||
|
-- Open database interface
|
||||||
|
keymap.set("n", "<leader>db", function()
|
||||||
|
require("dbee").open()
|
||||||
|
end, { desc = "Open Database Interface" })
|
||||||
|
|
||||||
|
-- Close database interface
|
||||||
|
keymap.set("n", "<leader>dc", function()
|
||||||
|
require("dbee").close()
|
||||||
|
end, { desc = "Close Database Interface" })
|
||||||
|
|
||||||
|
-- Execute current query (when in database editor)
|
||||||
|
keymap.set("n", "<leader>dq", function()
|
||||||
|
require("dbee").api.ui.execute_query()
|
||||||
|
end, { desc = "Execute Query" })
|
||||||
|
|
||||||
|
-- Store results to file
|
||||||
|
keymap.set("n", "<leader>ds", function()
|
||||||
|
require("dbee").store("csv", "file", { extra_arg = "~/query_results.csv" })
|
||||||
|
end, { desc = "Store Results to File" })
|
||||||
|
|
||||||
|
-- Yank results to clipboard
|
||||||
|
keymap.set("n", "<leader>dy", function()
|
||||||
|
require("dbee").store("json", "yank", {})
|
||||||
|
end, { desc = "Yank Results to Clipboard" })
|
||||||
|
|
||||||
|
-- =============================================================================
|
||||||
|
-- NVIM-DBEE INTERNAL KEYMAPS
|
||||||
|
-- =============================================================================
|
||||||
|
|
||||||
|
-- Set up nvim-dbee internal keymaps
|
||||||
|
local function setup_dbee_keymaps()
|
||||||
|
-- Drawer mappings (left panel)
|
||||||
|
keymap.set("n", "<CR>", function()
|
||||||
|
require("dbee").api.ui.open_connection()
|
||||||
|
end, { buffer = true, desc = "Open Connection" })
|
||||||
|
|
||||||
|
keymap.set("n", "a", function()
|
||||||
|
require("dbee").api.ui.add_connection()
|
||||||
|
end, { buffer = true, desc = "Add Connection" })
|
||||||
|
|
||||||
|
keymap.set("n", "e", function()
|
||||||
|
require("dbee").api.ui.edit_connection()
|
||||||
|
end, { buffer = true, desc = "Edit Connection" })
|
||||||
|
|
||||||
|
keymap.set("n", "d", function()
|
||||||
|
require("dbee").api.ui.delete_connection()
|
||||||
|
end, { buffer = true, desc = "Delete Connection" })
|
||||||
|
|
||||||
|
keymap.set("n", "r", function()
|
||||||
|
require("dbee").api.ui.refresh_connections()
|
||||||
|
end, { buffer = true, desc = "Refresh Connections" })
|
||||||
|
|
||||||
|
-- Editor mappings (query editor)
|
||||||
|
keymap.set("n", "BB", function()
|
||||||
|
require("dbee").api.ui.execute_query()
|
||||||
|
end, { buffer = true, desc = "Execute Query" })
|
||||||
|
|
||||||
|
keymap.set("n", "cc", function()
|
||||||
|
require("dbee").api.ui.clear_results()
|
||||||
|
end, { buffer = true, desc = "Clear Results" })
|
||||||
|
|
||||||
|
keymap.set("n", "ss", function()
|
||||||
|
require("dbee").api.ui.save_scratchpad()
|
||||||
|
end, { buffer = true, desc = "Save Scratchpad" })
|
||||||
|
|
||||||
|
-- Result mappings (results buffer)
|
||||||
|
keymap.set("n", "L", function()
|
||||||
|
require("dbee").api.ui.result_page_next()
|
||||||
|
end, { buffer = true, desc = "Next Page" })
|
||||||
|
|
||||||
|
keymap.set("n", "H", function()
|
||||||
|
require("dbee").api.ui.result_page_prev()
|
||||||
|
end, { buffer = true, desc = "Previous Page" })
|
||||||
|
|
||||||
|
keymap.set("n", "F", function()
|
||||||
|
require("dbee").api.ui.result_page_first()
|
||||||
|
end, { buffer = true, desc = "First Page" })
|
||||||
|
|
||||||
|
keymap.set("n", "E", function()
|
||||||
|
require("dbee").api.ui.result_page_last()
|
||||||
|
end, { buffer = true, desc = "Last Page" })
|
||||||
|
|
||||||
|
keymap.set("n", "yaj", function()
|
||||||
|
require("dbee").api.ui.yank_row_json()
|
||||||
|
end, { buffer = true, desc = "Yank Row as JSON" })
|
||||||
|
|
||||||
|
keymap.set("n", "yac", function()
|
||||||
|
require("dbee").api.ui.yank_row_csv()
|
||||||
|
end, { buffer = true, desc = "Yank Row as CSV" })
|
||||||
|
|
||||||
|
keymap.set("n", "yaJ", function()
|
||||||
|
require("dbee").api.ui.yank_all_json()
|
||||||
|
end, { buffer = true, desc = "Yank All as JSON" })
|
||||||
|
|
||||||
|
keymap.set("n", "yaC", function()
|
||||||
|
require("dbee").api.ui.yank_all_csv()
|
||||||
|
end, { buffer = true, desc = "Yank All as CSV" })
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Apply dbee keymaps when dbee buffers are created
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
pattern = { "dbee-drawer", "dbee-editor", "dbee-result" },
|
||||||
|
callback = setup_dbee_keymaps,
|
||||||
|
})
|
||||||
@@ -29,12 +29,13 @@ return {
|
|||||||
|
|
||||||
-- 📂 Set menu with improved icons
|
-- 📂 Set menu with improved icons
|
||||||
dashboard.section.buttons.val = {
|
dashboard.section.buttons.val = {
|
||||||
dashboard.button("e", "📜 New File", "<cmd>ene<CR>"),
|
dashboard.button("f", "🔎 Find File", "<cmd>Telescope find_files<CR>"),
|
||||||
dashboard.button("SPC ee", "📂 File Explorer", "<cmd>NvimTreeToggle<CR>"),
|
dashboard.button("n", "📜 New File", "<cmd>ene<CR>"),
|
||||||
dashboard.button("SPC ff", "🔎 Find File", "<cmd>Telescope find_files<CR>"),
|
dashboard.button("g", "📝 Find Text", "<cmd>Telescope live_grep<CR>"),
|
||||||
dashboard.button("SPC fs", "📝 Find Word", "<cmd>Telescope live_grep<CR>"),
|
dashboard.button("r", "📚 Recent Files", "<cmd>Telescope oldfiles<CR>"),
|
||||||
dashboard.button("SPC wr", "💾 Restore Session", "<cmd>SessionRestore<CR>"),
|
dashboard.button("c", "⚙️ Config", "<cmd>e ~/.config/nvim/init.lua<CR>"),
|
||||||
dashboard.button("q", "❌ Quit NVIM", "<cmd>qa<CR>"),
|
dashboard.button("L", "🦥 Lazy", "<cmd>Lazy<CR>"),
|
||||||
|
dashboard.button("q", "🚪 Quit", "<cmd>qa<CR>"),
|
||||||
}
|
}
|
||||||
|
|
||||||
-- 🎯 Function to center text within a width
|
-- 🎯 Function to center text within a width
|
||||||
|
|||||||
@@ -1,178 +1,75 @@
|
|||||||
-- Temporarily disabled to fix database error
|
|
||||||
-- return {
|
|
||||||
-- -- =============================================================================
|
|
||||||
-- -- DATABASE PLUGINS
|
|
||||||
-- -- =============================================================================
|
|
||||||
|
|
||||||
-- -- Database client for Neovim
|
|
||||||
-- {
|
|
||||||
-- "tpope/vim-dadbod",
|
|
||||||
-- dependencies = {
|
|
||||||
-- "kristijanhusak/vim-dadbod-ui",
|
|
||||||
-- "kristijanhusak/vim-dadbod-completion",
|
|
||||||
-- },
|
|
||||||
-- config = function()
|
|
||||||
-- -- Dadbod UI configuration
|
|
||||||
-- vim.g.db_ui_use_nerd_fonts = 1
|
|
||||||
-- vim.g.db_ui_winwidth = 30
|
|
||||||
-- vim.g.db_ui_winposition = "right"
|
|
||||||
-- vim.g.db_ui_show_help = 0
|
|
||||||
-- vim.g.db_ui_auto_execute_table_helpers = 1
|
|
||||||
|
|
||||||
-- -- Disable auto-connection to prevent errors
|
|
||||||
-- vim.g.db_ui_auto_execute_table_helpers = 0
|
|
||||||
-- vim.g.db_ui_show_database_icon = 0
|
|
||||||
-- vim.g.db_ui_winwidth = 30
|
|
||||||
-- vim.g.db_ui_winposition = "right"
|
|
||||||
-- vim.g.db_ui_use_nerd_fonts = 1
|
|
||||||
-- vim.g.db_ui_show_help = 0
|
|
||||||
|
|
||||||
-- -- Disable automatic database loading
|
|
||||||
-- vim.g.db_ui_auto_execute_table_helpers = 0
|
|
||||||
-- vim.g.db_ui_show_database_icon = 0
|
|
||||||
-- vim.g.db_ui_auto_execute_table_helpers = 0
|
|
||||||
-- vim.g.db_ui_show_database_icon = 0
|
|
||||||
|
|
||||||
-- vim.g.db_ui_table_helpers = {
|
|
||||||
-- sqlite = {
|
|
||||||
-- count = "SELECT COUNT(*) FROM {table}",
|
|
||||||
-- explain = "EXPLAIN QUERY PLAN {last_query}",
|
|
||||||
-- indexes = "PRAGMA index_list({table})",
|
|
||||||
-- show = "PRAGMA table_info({table})",
|
|
||||||
-- size = "SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size() WHERE name = '{table}'",
|
|
||||||
-- },
|
|
||||||
-- mysql = {
|
|
||||||
-- count = "SELECT COUNT(*) FROM {table}",
|
|
||||||
-- explain = "EXPLAIN {last_query}",
|
|
||||||
-- indexes = "SHOW INDEX FROM {table}",
|
|
||||||
-- show = "SHOW CREATE TABLE {table}",
|
|
||||||
-- size = "SELECT ROUND(((data_length + index_length) / 1024 / 1024), 2) AS 'Size (MB)' FROM information_schema.TABLES WHERE table_schema = '{database}' AND table_name = '{table}'",
|
|
||||||
-- },
|
|
||||||
-- postgresql = {
|
|
||||||
-- count = "SELECT COUNT(*) FROM {table}",
|
|
||||||
-- explain = "EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON) {last_query}",
|
|
||||||
-- indexes = "SELECT indexname, indexdef FROM pg_indexes WHERE tablename = '{table}'",
|
|
||||||
-- show = "\\d {table}",
|
|
||||||
-- size = "SELECT pg_size_pretty(pg_total_relation_size('{table}'))",
|
|
||||||
-- },
|
|
||||||
-- redis = {
|
|
||||||
-- count = "LLEN {table}",
|
|
||||||
-- explain = "SLOWLOG GET 10",
|
|
||||||
-- indexes = "KEYS *",
|
|
||||||
-- show = "TYPE {table}",
|
|
||||||
-- size = "MEMORY USAGE {table}",
|
|
||||||
-- },
|
|
||||||
-- }
|
|
||||||
|
|
||||||
-- -- Dadbod completion
|
|
||||||
-- vim.g.vim_dadbod_completion_mark = "📊"
|
|
||||||
|
|
||||||
-- -- Configure database adapters
|
|
||||||
-- vim.g.db_adapter_sqlite = 'sqlite3'
|
|
||||||
-- vim.g.db_adapter_mysql = 'mysql'
|
|
||||||
-- vim.g.db_adapter_postgresql = 'psql'
|
|
||||||
-- vim.g.db_adapter_redis = 'redis-cli'
|
|
||||||
|
|
||||||
-- -- Disable automatic database connections
|
|
||||||
-- vim.g.db_ui_auto_execute_table_helpers = 0
|
|
||||||
-- vim.g.db_ui_show_database_icon = 0
|
|
||||||
-- end,
|
|
||||||
-- },
|
|
||||||
|
|
||||||
-- -- SQL formatting and syntax highlighting
|
|
||||||
-- {
|
|
||||||
-- "b4winckler/vim-objc",
|
|
||||||
-- ft = { "sql", "mysql", "postgresql" },
|
|
||||||
-- },
|
|
||||||
|
|
||||||
-- -- SQL formatting with sqlparse
|
|
||||||
-- {
|
|
||||||
-- "b4winckler/vim-objc",
|
|
||||||
-- ft = { "sql" },
|
|
||||||
-- config = function()
|
|
||||||
-- vim.g.sqlformat_command = "sqlformat"
|
|
||||||
-- vim.g.sqlformat_options = "-r -k upper"
|
|
||||||
-- end,
|
|
||||||
-- },
|
|
||||||
-- }
|
|
||||||
|
|
||||||
-- Return empty table to prevent errors
|
|
||||||
return {
|
return {
|
||||||
-- =============================================================================
|
-- =============================================================================
|
||||||
-- DATABASE PLUGINS
|
-- DATABASE PLUGINS
|
||||||
-- =============================================================================
|
-- =============================================================================
|
||||||
|
|
||||||
-- Database client for Neovim
|
-- Modern database client for Neovim (replaces vim-dadbod)
|
||||||
{
|
{
|
||||||
"tpope/vim-dadbod",
|
"kndndrj/nvim-dbee",
|
||||||
|
build = function()
|
||||||
|
-- Install the Go binary
|
||||||
|
require("dbee").install()
|
||||||
|
end,
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"kristijanhusak/vim-dadbod-ui",
|
"nvim-lua/plenary.nvim",
|
||||||
"kristijanhusak/vim-dadbod-completion",
|
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
-- Disable all automatic database operations
|
require("dbee").setup({
|
||||||
vim.g.db_ui_auto_execute_table_helpers = 0
|
-- Sources for database connections
|
||||||
vim.g.db_ui_show_database_icon = 0
|
sources = {
|
||||||
vim.g.db_ui_use_nerd_fonts = 1
|
-- Load connections from memory (only guaranteed working connections)
|
||||||
vim.g.db_ui_winwidth = 30
|
require("dbee.sources").MemorySource:new({
|
||||||
vim.g.db_ui_winposition = "right"
|
-- PostgreSQL (confirmed working)
|
||||||
vim.g.db_ui_show_help = 0
|
{
|
||||||
|
name = "mock_api",
|
||||||
-- Disable automatic database loading completely
|
type = "postgres",
|
||||||
vim.g.db_ui_auto_execute_table_helpers = 0
|
url = "postgres://localhost:5432/mock_api?sslmode=disable",
|
||||||
vim.g.db_ui_show_database_icon = 0
|
},
|
||||||
|
}),
|
||||||
-- Configure table helpers (only used when manually triggered)
|
-- Load connections from environment variable (for dynamic connections)
|
||||||
vim.g.db_ui_table_helpers = {
|
require("dbee.sources").EnvSource:new("DBEE_CONNECTIONS"),
|
||||||
sqlite = {
|
-- Load connections from file (persistent storage - user-added connections)
|
||||||
count = "SELECT COUNT(*) FROM {table}",
|
require("dbee.sources").FileSource:new(vim.fn.stdpath("cache") .. "/dbee/persistence.json"),
|
||||||
explain = "EXPLAIN QUERY PLAN {last_query}",
|
|
||||||
indexes = "PRAGMA index_list({table})",
|
|
||||||
show = "PRAGMA table_info({table})",
|
|
||||||
size = "SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size() WHERE name = '{table}'",
|
|
||||||
},
|
},
|
||||||
mysql = {
|
|
||||||
count = "SELECT COUNT(*) FROM {table}",
|
-- UI Configuration
|
||||||
explain = "EXPLAIN {last_query}",
|
ui = {
|
||||||
indexes = "SHOW INDEX FROM {table}",
|
-- Layout configuration
|
||||||
show = "SHOW CREATE TABLE {table}",
|
layout = {
|
||||||
size = "SELECT ROUND(((data_length + index_length) / 1024 / 1024), 2) AS 'Size (MB)' FROM information_schema.TABLES WHERE table_schema = '{database}' AND table_name = '{table}'",
|
-- Drawer (left panel) width
|
||||||
|
drawer_width = 30,
|
||||||
|
-- Result buffer height
|
||||||
|
result_height = 15,
|
||||||
|
-- Editor buffer height
|
||||||
|
editor_height = 10,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
postgresql = {
|
|
||||||
count = "SELECT COUNT(*) FROM {table}",
|
-- Database configuration
|
||||||
explain = "EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON) {last_query}",
|
database = {
|
||||||
indexes = "SELECT indexname, indexdef FROM pg_indexes WHERE tablename = '{table}'",
|
-- Default page size for results
|
||||||
show = "\\d {table}",
|
page_size = 100,
|
||||||
size = "SELECT pg_size_pretty(pg_total_relation_size('{table}'))",
|
-- Connection timeout in seconds
|
||||||
|
timeout = 30,
|
||||||
|
-- Maximum number of connections
|
||||||
|
max_connections = 5,
|
||||||
},
|
},
|
||||||
redis = {
|
|
||||||
count = "LLEN {table}",
|
-- Logging configuration
|
||||||
explain = "SLOWLOG GET 10",
|
log = {
|
||||||
indexes = "KEYS *",
|
-- Log level: "debug", "info", "warn", "error"
|
||||||
show = "TYPE {table}",
|
level = "info",
|
||||||
size = "MEMORY USAGE {table}",
|
-- Log file path
|
||||||
|
file = vim.fn.stdpath("cache") .. "/dbee/dbee.log",
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
-- Dadbod completion
|
|
||||||
vim.g.vim_dadbod_completion_mark = "📊"
|
|
||||||
|
|
||||||
-- Configure database adapters
|
|
||||||
vim.g.db_adapter_sqlite = 'sqlite3'
|
|
||||||
vim.g.db_adapter_mysql = 'mysql'
|
|
||||||
vim.g.db_adapter_postgresql = 'psql'
|
|
||||||
vim.g.db_adapter_redis = 'redis-cli'
|
|
||||||
|
|
||||||
-- Ensure no automatic connections
|
|
||||||
vim.g.db_ui_auto_execute_table_helpers = 0
|
|
||||||
vim.g.db_ui_show_database_icon = 0
|
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
-- SQL formatting and syntax highlighting
|
-- SQL formatting and syntax highlighting
|
||||||
{
|
{
|
||||||
"b4winckler/vim-objc",
|
"b4winckler/vim-objc",
|
||||||
ft = { "sql", "mysql", "postgresql" },
|
ft = { "sql", "mysql", "postgresql", "oracle" },
|
||||||
},
|
},
|
||||||
|
|
||||||
-- SQL formatting with sqlparse
|
-- SQL formatting with sqlparse
|
||||||
@@ -184,4 +81,52 @@ return {
|
|||||||
vim.g.sqlformat_options = "-r -k upper"
|
vim.g.sqlformat_options = "-r -k upper"
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
-- MongoDB syntax highlighting (without LSP)
|
||||||
|
{
|
||||||
|
"neovim/nvim-lspconfig",
|
||||||
|
ft = { "javascript", "json" },
|
||||||
|
config = function()
|
||||||
|
-- Enable MongoDB syntax highlighting for .js files
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
pattern = { "javascript", "json" },
|
||||||
|
callback = function()
|
||||||
|
vim.bo.filetype = "javascript"
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Redis syntax highlighting
|
||||||
|
{
|
||||||
|
"neovim/nvim-lspconfig",
|
||||||
|
ft = { "redis" },
|
||||||
|
config = function()
|
||||||
|
-- Enable Redis syntax highlighting
|
||||||
|
vim.api.nvim_create_autocmd("BufRead,BufNewFile", {
|
||||||
|
pattern = "*.redis",
|
||||||
|
callback = function()
|
||||||
|
vim.bo.filetype = "redis"
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- CQL (Cassandra Query Language) syntax highlighting
|
||||||
|
{
|
||||||
|
"neovim/nvim-lspconfig",
|
||||||
|
ft = { "cql" },
|
||||||
|
config = function()
|
||||||
|
-- Enable CQL syntax highlighting
|
||||||
|
vim.api.nvim_create_autocmd("BufRead,BufNewFile", {
|
||||||
|
pattern = "*.cql",
|
||||||
|
callback = function()
|
||||||
|
vim.bo.filetype = "cql"
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,10 @@ return {
|
|||||||
"tailwindcss",
|
"tailwindcss",
|
||||||
-- Database language servers
|
-- Database language servers
|
||||||
"sqls", -- SQL language server
|
"sqls", -- SQL language server
|
||||||
"mongols", -- MongoDB language server
|
"mongodb", -- MongoDB language server
|
||||||
|
"redis", -- Redis language server
|
||||||
|
"oracle", -- Oracle language server
|
||||||
|
"cassandra", -- Cassandra language server
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user