Minimal Multi database client for Neovim
- These dependencies are required to be installed:
Go
. - Java is not required. Only if you want to use databases which require Java, in that case
Java 21 or newer
andMaven
are required. - For the sake of simplicity, this plugin is STATELESS. It does not use database sessions or keep states after Neovim is closed.
- This plugin has been developed on and for
Linux
following open source philosophy.
Database | Supported | Language required | NOTE |
---|---|---|---|
MongoDB | ✔️ | Go | Supported operations detailed here |
MySQL | ✔️ | Go | Supported operations detailed here |
MS-SQL | ✔️ | Go | Supported operations detailed here |
PostgreSQL | ✔️ | Go | Supported operations detailed here |
Neo4j | ❌ | Go | Future release |
Oracle | ❌ | Go | Future release |
Redis | ❌ | Go | Future release |
SQLite | ❌ | Go | Future release |
IBM Informix | ✔️ | Java | Supported operations detailed here |
NOTE: The colorscheme nox from nvim-nyctophilia is used in this image.
Lazy
{
'javiorfo/nvim-tabula',
dependencies = {
'javiorfo/nvim-popcorn',
'javiorfo/nvim-spinetta'
},
lazy = true,
cmd = { "TabulaBuild" },
ft = { "sql", "javascript" }, -- javascript if MongoDB is used
build = function()
-- Update the backend in every plugin change
require'tabula.core'.build()
end,
opts = {
-- This section is not required
-- Only if you want to change default configurations
-- Default keymaps
commands = {
-- Keymap in Normal mode to change DB with command :TabulaSelectDB
select_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>',
},
-- Command :TabulaShowDB
view = {
-- Show the user name
show_user = true,
-- Show the user password
show_password = true,
},
-- Output buffer
output = {
-- Default dest folder where .tabula 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,
},
-- 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
}
}
}
- 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", "mysql", "mssql" and "informix".
Lazy
opts = {
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",
},
{
name = "PostgreSQL example",
engine = "postgres",
dbname = "db_dummy",
user = "admin",
password = "admin",
},
{
name = "MS-SQL 1",
engine = "mssql",
dbname = "db_dummy",
},
{
name = "MySQL something",
engine = "mysql",
dbname = "db_dummy",
user = "admin",
password = "admin",
},
}
}
}
- 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.
Lazy
opts = {
db = dofile(os.getenv("HOME") .. "/path/to/connections.lua")
-- connections.lua will have something like
-- return {
-- default = 1,
-- connections = {
-- {...} -- here complete the connection data
-- }
-- }
}
- 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)
- 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)
db.mycollection.find({ "field1": "value1" }).sort({"info": -1})
// "db." is optional in nvim-tabula. This will work too
mycollection.find({ "field1": "value1" }).sort({"info": -1})
NOTE: The colorscheme nox from nvim-nyctophilia is used in this image.
- When a sql file or js file (in case of Mongo) is opened, Neovim will print what connection is set by default in nvim-tabula. 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.
- This is executed when this plugin receives and update, not necessary to be executed manually except if nvim-tabula informs it.
- Command to close all opened .tabula. Not necessary to execute it manually. It's called by this command:
commands = {
-- Keymap in Normal mode to close all buffer results
close = '<C-c>',
},
-- Show a popup with the DB info (name, engine, host, port, credentials)
- Show the logs
- Command to execute queries. Not necessary to execute it manually. It's called by this command:
commands = {
-- Keymap in Normal and Visual mode to execute a query
execute = '<C-t>',
},
- Command to change the DB connection to another.
NOTE: The colorscheme nox from nvim-nyctophilia is used in this image.
- This command has an autocomplete menu showing all the tables of the selected database
- If you press enter after a table was selected, a popup show the "selected table" info
NOTE: The colorscheme nox from nvim-nyctophilia is used in this image.
Logs are saved generally in this path: /home/your_user/.local/state/nvim/tabula.log
- To check the logs execute the command
:TabulaLogs
NOTE: Only error logs are saved. If you want to enable debug phase, enable this on setup configuration:
require'tabula'.setup {
internal = {
log_debug = true
}
}
- Note that in the fourth statement there is a duplicated primary key error reported
NOTE: The colorscheme nox from nvim-nyctophilia is used in this image.
- Bitcoin (QR)
1GqdJ63RDPE4eJKujHi166FAyigvHu5R7v