1
0
Fork
You've already forked nvim-dbeer
0
Minimal Multi database (SQL, NoSQL, Graph) client for Neovim (Native & ODBC)
  • Go 59%
  • Lua 37.2%
  • Shell 2%
  • Vim Script 1.8%
Find a file
2026年06月20日 20:29:38 -03:00
ftdetect redis and neo 2026年04月04日 21:41:52 -03:00
ftplugin redis and neo 2026年04月04日 21:41:52 -03:00
go loops performance 2026年06月20日 20:29:38 -03:00
lua on_error added 2026年05月27日 14:00:06 -03:00
plugin remove telescope 2026年05月26日 13:09:42 -03:00
script redis and neo 2026年04月04日 21:41:52 -03:00
syntax go neo + dyn modules 2026年04月03日 23:27:48 -03:00
tests/script name changed 2024年10月19日 15:50:09 -03:00
.gitignore redis and neo 2026年04月04日 21:41:52 -03:00
LICENSE codeberg 2026年04月13日 17:14:50 -03:00
README.md readme 2026年05月26日 13:06:27 -03:00

nvim-dbeer

Minimal Multi database client for Neovim

Caveats

  • These dependencies are required to be installed: Go (1.26), unixodbc (optional for ODBC).
  • For the sake of simplicity, this plugin is STATELESS. It does not use database sessions or keep states after Neovim is closed.
  • Considering compilation times, the crates belonging to each engine will be downloaded only when the engine configuration is required by the user. For example, if you only use Postgres, only the Postgres module will be configured in the Go backend. This allows faster compilation times and a smaller binary.
  • This plugin has been developed on and for Linux following open source philosophy.

Supported Databases

Databases not marked will be supported in the future

Database Supported Connection NOTE
IBM DB2 ✔️ ODBC Supported operations detailed here
IBM Informix ✔️ ODBC Supported operations detailed here
MariaDB ✔️ Built-in Supported operations detailed here
MongoDB ✔️ Built-in Supported operations detailed here
MS-SQL ✔️ Built-in Supported operations detailed here
MySQL ✔️ Built-in Supported operations detailed here
Neo4j ✔️ Built-in Supported
Oracle ✔️ Built-in Supported operations detailed here
PostgreSQL ✔️ Built-in Supported operations detailed here
Redis ✔️ Built-in Supported operations detailed here
SQLite ✔️ Built-in Supported operations detailed here

Demo

nvim-dbeer

NOTE: The colorscheme nox from nvim-nyctophilia is used in this image.


Table of Contents


Installation

vim.api.nvim_create_autocmd('PackChanged', {
 callback = function(ev)
 local name, kind = ev.data.spec.name, ev.data.kind
 if name == 'nvim-dbeer' and kind == 'update' then
 if not ev.data.active then vim.cmd.packadd('nvim-dbeer') end
 require 'dbeer.core'.reload()
 end
 end
})
vim.pack.add {
 "https://codeberg.org/caskstrength/nvim-dbeer",
 "https://codeberg.org/caskstrength/nvim-popcorn",
 "https://codeberg.org/caskstrength/nvim-spinetta",
}
require("dbeer").setup {
 -- This section is not required
 -- Only if you want to change default configurations
 
 -- Default keymaps
 commands = {
 -- Keymap in Normal mode to select DB with command :DBeerDB
 select_db = '<CR>',
 
 -- Keymap in Normal mode to expand and show connection data from DB with command :DBeerDB
 expand_db = '<C-space>',
 
 -- Keymap in Normal and Visual mode to execute a query
 execute = '<C-t>',
 
 -- Keymap in Normal mode to close all buffer results
 close = '<C-c>',
 -- Keymap in Normal mode to scroll left dbeer query results
 scroll_left = '<C-h>',
 -- Keymap in Normal mode to scroll right dbeer query results
 scroll_rigth = '<C-l>',
 -- Keymap in Normal mode to scroll down dbeer query results
 scroll_down = '<C-j>',
 -- Keymap in Normal mode to scroll up dbeer query results
 scroll_up = '<C-k>',
 },
 -- Command :DBeerDB
 view = {
 -- Show the user name
 show_user = true,
 
 -- Show the user password
 show_password = true,
 },
 -- Output buffer
 output = {
 -- Default dest folder where .dbeer files are created
 -- The results will be erased after closing the buffer
 -- If you want to keep the query results, change this to a personal folder
 dest_folder = "/tmp",
 -- Border style of the table result (1 to 6 to choose)
 -- Single border, rounded corners, double border, etc
 border_style = 1,
 -- A "hi link column style" in header table results
 header_style_link = "Type",
 -- Height of the buffer table result
 buffer_height = 20,
 -- Override the results buffer
 -- If false every query opens in a different buffer
 override = false,
 },
 -- Configuration of databases (host, port, credentials, etc)
 db = {
 -- Default DB when open a buffer
 default = 1,
 -- connections are left empty by default
 -- because these values are DB data connections set by the user
 -- connections = {}
 },
 -- For errors and debug purposes if anything goes wrong
 internal = {
 -- Disabled by default
 log_debug = false
 }
}

Configuration

Configure DB connections and credentials

  • In the setup show above there is a section left out to be configured by the user (connections inside db table).
  • Here are some examples of different DB configurations
  • Engines possible values are: mongo, postgres, oracle, mysql, redis, sqlite, mssql, neo4j, db2 and informix.
require("dbeer").setup {
 db = {
 -- Here when open a sql file (or js file in Mongo case) connection will set to 2nd element (postgres)
 default = 2,
 
 -- Required fields are:
 -- name, engine and dbname
 -- host and port will be the default in each engine if not set
 -- user and password are optional
 connections = {
 {
 name = "MongoDB some name",
 engine = "mongo",
 host = "123.4.1.8",
 port = "27016",
 dbname = "db_dummy",
 user = "admin",
 password = "admin",
 conn_query= "/?authSource=admin" -- Option to add query strings to connection
 },
 {
 name = "PostgreSQL example",
 engine = "postgres",
 dbname = "db_dummy",
 user = "admin",
 password = "admin",
 },
 {
 name = "Oracle example",
 engine = "oracle",
 dbname = "db_dummy",
 user = "admin",
 password = "admin",
 },
 {
 name = "MS-SQL example",
 engine = "mssql",
 dbname = "db_dummy",
 },
 {
 name = "SQLite example",
 engine = "sqlite",
 dbname = "/path/to/db_dummy.db", -- 'dbname' must contain the absolute path to the .db file or use ":memory:"
 },
 {
 name = "MySQL example",
 engine = "mysql", -- "mysql" also works for MariaDB 
 dbname = "db_dummy",
 user = "admin",
 password = "admin",
 },
 {
 name = "Redis example",
 engine = "redis", 
 dbname = "1",
 user = "admin",
 password = "admin",
 },
 {
 name = "Neo4j example",
 engine = "neo4j", 
 host = "neohost.com"
 port = "7687",
 dbname = "db_dummy",
 user = "admin",
 password = "admin",
 },
 -- IBM Informix needs ODBC connection configured (check unix ODBC docs for this)
 {
 name = "Informix example",
 engine = "informix",
 dbname = "Informix_ODBC", -- 'dbname' must match your DSN
 user = "some-user",
 password = "1234",
 },
 -- IBM DB2 needs ODBC connection configured (check unix ODBC docs for this)
 {
 name = "DB2 example",
 engine = "db2",
 dbname = "DB2_ODBC", -- 'dbname' must match your DSN
 },
 }
 }
}
  • I personally recommend having connections in the same folder where the sql or js scripts are stored. So you can check or set connections in the same folder you have database scripts.
require("dbeer").setup {
 db = dofile(os.getenv("HOME") .. "/path/to/connections.lua")
}
-- /path/to/connections.lua
 -- connections.lua will have something like
-- return {
-- default = 1,
-- connections = {
-- {...} -- here complete the connection data
-- }
-- }

Supported Operations

Sql

  • All select and subselect queries
  • Commands insert, update, delete, create, modify, etc
  • Comments (queries with comments could not be processed)
  • Execution of multiple semicolon-separated queries
    • Commands insert, update, delete, create, modify, etc
    • Select statements
  • Command to list tables
  • Command to get table info (fields, pk, fk, data type, etc)

Redis

  • Using .rdb file extension
  • Operations
    • "GET"
    • "SET"
    • "DEL" one of multiple
    • "EXISTS"
    • "KEYS" pattern
    • "EXPIRE" with seconds
    • "TTL"
    • "FLUSHALL"
    • String operations
    • List operations
    • Hash operations
    • Sorted operations
  • Comments (queries with comments could not be processed)
  • Execution of multiple semicolon-separated queries
  • Command to list collections
  • Command to get collection info (fields, data type, etc)

NoSql

  • Operations
    • "find" with filters and subsequet "sort", "skip" or "limit"
    • "countDocuments"
    • "findOne" with filters
    • "insertOne"
    • "deleteOne"
    • "updateOne"
    • "insertMany"
    • "deleteMany"
    • "updateMany"
    • "drop" (drop collection)
    • Indexes operations
    • Replace operations
    • Rename operations
    • Aggregate operations
  • Comments (queries with comments could not be processed)
  • Execution of multiple semicolon-separated queries
  • Command to list collections
  • Command to get collection info (fields, data type, etc)
Example
db.mycollection.find({ "field1": "value1" }).sort({"info": -1})
// "db." is optional in nvim-dbeer. This will work too
mycollection.find({ "field1": "value1" }).sort({"info": -1})
nvim-dbeer

Usage

  • When a sql file or js file (in case of Mongo) is opened, Neovim will print what connection is set by default in nvim-dbeer. The connection to the database is done when the query is executed (open connection, execute statement, close connection), no session is set.
  • The keymap <C-t> (could be modified by the user, see config above) if executed in NORMAL mode will take all the script (semicolon-separated) to process. But maybe it's best to execute it in VISUAL mode getting the same experience of a stardard DB IDE where a query can be selected and execute it in isolation instead of the entire script.

Commands

DBeerLogs

  • Show the logs

DBeerDB

  • Command to change the DB connection to another one.
  • Show a expanded info of the DB (name, engine, host, port, credentials)
nvim-dbeer

DBeerTables

  • If you press enter after a table was selected, a popup show the "selected table" info
nvim-dbeer

NOTE: The colorscheme nox from nvim-nyctophilia is used in this image.


Tricks

As nvim-dbeer resets the default database connection everytime Neovim is close. There is a chance to set N scripts to X database everytime threy are opened. Using Neovim autocmd in init.lua:

-- Everytime test.sql, other.sql, update.sql are opened the default database is set to '2' 
vim.api.nvim_create_autocmd("BufReadPost", {
 pattern = { "test.sql", "other.sql", "update.sql" },
 callback = function()
 require 'dbeer'.default_db = 2
 end,
})

Logs

Logs are saved generally in this path: /home/your_user/.local/state/nvim/dbeer.log

  • To check the logs execute the command :dbeerLogs

NOTE: Only error logs are saved. If you want to enable debug phase, enable this on setup configuration:

require'dbeer'.setup {
 internal = {
 log_debug = true 
 }
}

Screenshots

Example executing the entire script (not select allowed) semicolon-separated

  • Note that in the fourth statement there is a duplicated primary key error reported nvim-dbeer

Example example of border style 4 in table result

nvim-dbeer