kndndrj / nvim-dbee Goto Github PK
View Code? Open in Web Editor NEWInteractive database client for neovim
License: GNU General Public License v3.0
Interactive database client for neovim
License: GNU General Public License v3.0
title
For example;
DELETE FROM <table>;
doesn't show anything in the result buffer;
│ Rows Affected
──┼───────────────
but the same statement in psql does;
dev=# DELETE FROM <table>;
DELETE <N>
When I try to open the UI, an error occurs:
DbeeGetCurrentConnection Vim:E475: Invalid value for argument cmd: 'dbee' is not executable
stack traceback:
^I[C]: at 0x562fee0b0130
^I[C]: in function 'pcall'
^I...ocal/share/nvim/lazy/nvim-dbee/lua/dbee/handler/init.lua:160: in function 'get_current_connection'
^I...al/share/nvim/lazy/nvim-dbee/lua/dbee/ui/drawer/init.lua:62: in function 'new'
^I....local/share/nvim/lazy/nvim-dbee/lua/dbee/entry/init.lua:93: in function 'setup_ui'
^I....local/share/nvim/lazy/nvim-dbee/lua/dbee/entry/init.lua:135: in function 'open_ui'
^I....local/share/nvim/lazy/nvim-dbee/lua/dbee/entry/init.lua:130: in function 'toggle_ui'
^I...e/troysigx/.local/share/nvim/lazy/nvim-dbee/lua/dbee.lua:24: in function 'toggle'
^I[string ":lua"]:1: in main chunk
Here is my config using lazy.nvim
:
{
'kndndrj/nvim-dbee',
dependencies = {
'MunifTanjim/nui.nvim',
},
build = function()
-- Install tries to automatically detect the install method.
-- if it fails, try calling it with one of these parameters:
-- "curl", "wget", "bitsadmin", "go"
require('dbee').install()
end,
config = function()
require('dbee').setup(--[[optional config]])
end,
}
Nullable columns seem to print the address of a pointer in a table view of results, instead of the stored value or null.
But the values are copied ok, when yanking json with hotkeys.
This is kind of 3 parter:
It would be ideal if it could pull a password from pass on linux, and/or read them from environment variables. I use doppler a lot at work, so it would be convenient for me to just configure connections using environment variable substitution and then I can run nvim with doppler to get those variables. for example:
connections = {
-- example:
-- {
-- name = "example-pg",
-- type = "postgres",
-- url = "postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}",
-- },
or maybe if you just have your own internal way of specifying placeholders for secrets, you can then add a separate section for secrets, like:
connections = {
example:
{
name = "example-pg",
type = "postgres",
url = "postgres://{{SECRET_USER}}:{{SECRET_PASSWORD}}host:5432/mydb",
secrets: {
user: { source="env", key="WORK_DB_USER" }, -- pull from environment variables
password: { source="pass", key="work_db_password" } -- pull from `pass`
}
},
Hello Everyone,
This is request to integrate with Nvim Tree, that connection tree list will be open under same tree as Nvim Tree for easy navigation.
The save to csv/json is a great feature, but often we might want to use the results in an existing buffer.
It's faffy to save somewhere, load that in a buffer, select and yank, paste it into the buffer we wanted it in, then go back to delete the saved buffer from disk and vim.
It would be really helpful to be able to yank-as-csv or yank-as-json from the results buffer, then we could simply paste it where we want it.
It would be super great if we could also yank a row or selected rows of the output, too, but I suspect that's a much bigger fetaure!
When yanking a reasonable amount of results (i had 200+) using a CSV formatter only parts of the data appear in the register.
I assume it happens because Go CSV writer uses a buffered writer, which flushes buffered data whenever it reaches a certain threshold (4096 bytes i think), which in turn triggers setreg
call on each flush.
I managed to workaround it with a local copy of a plugin using a bytes.Buffer
instead of a register
as a io.Writer
and writing resulting bytes to the register
:
func (yo *YankRegisterOutput) Write(result models.Result) error {
writer := new(bytes.Buffer)
err := yo.formatter.Format(result, writer)
if err != nil {
return err
}
reg := newRegister(yo.vim)
_, err = reg.Write(writer.Bytes())
return err
}
I'm nowhere near a proficient level in Go though, so maybe there's a better solution to this :)
P.S.: Really loving this plugin! Let me know if I can help with anything.
Tried to install nvim-dbee to my LunarVim via packer by adding this configuration to my configs:
{
"kndndrj/nvim-dbee",
requires = {
"MunifTanjim/nui.nvim",
},
run = function()
-- Install tries to automatically detect the install method.
-- if it fails, try calling it with one of these parameters:
-- "curl", "wget", "bitsadmin", "go"
require("dbee").install()
end,
config = function()
require("dbee").setup( --[[optional config]])
end
},
but got this error when installing the package:
And this error when starting LunarVim (which is weird as I don't use lazy, I use packer):
My versions:
NVIM v0.9.5
LunarVim 1.3
Excited to try this, but on entering my mysql connection details I get
[init]: function Dbee_register_connection[1]..remote#define#request, line 2: Vim(let):Unable to connect to database: default addr
for network '127.0.0.1:13306' unknown
My config:
{
"kndndrj/nvim-dbee",
dependencies = { "MunifTanjim/nui.nvim", },
build = function()
require("dbee").install()
end,
config = function()
require("dbee").setup({
connections = {
{
name = "Something",
type = "mysql",
url = "mysql://root:[email protected]:13306/my_database",
}
}
})
end,
},
The credentials, the port are correct and work from the command line with the standard mysql
client.I've tried localhost
and 0.0.0.0
too.
Could this be a bug? Or am I doing something wrong?
I have several queries I like to run periodically which are not specific to any table, but rather the database as a whole, e.g. for "active queries"
SELECT
pid,
usename,
age(clock_timestamp(), query_start) AS started_at,
query
FROM pg_stat_activity
WHERE state = 'active' AND query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start DESC;
It would be nice to have an extra_helpers
configuration option at the database level rather than the table level
It looks like snowflake has a go driver available: https://docs.snowflake.com/developer-guide/golang/go-driver
which would be a fantastic edition to this plugin. Thank you for your consideration!
title
There seems to be an issue with the BigQuery adapter, where the results are not able to render fully. This seems possibly due to how the BigQuery row iterator is used in relation to the hasNext check required for iterators.
Failed retrieving results after 0.753 seconds
Reason:
no more items in iterator
Running a minimal example to reproduce (no additional connection configuration needed, except :
.
I noticed that in the result go code, there is this part where hasNext would be used after the results builder is generated -> https://github.com/kndndrj/nvim-dbee/blob/master/dbee/core/result.go#L49-L58 and wonder if the native BigQuery Done
error being returned here -> https://github.com/kndndrj/nvim-dbee/blob/master/dbee/adapters/bigquery_driver.go#L55-L61 is incorrectly being interacted with.
A recently introduced change has broken my ability to open the ui tray. An attempts result in the following error
E5108: Error executing lua function DbeeGetCurrentConnection[1]..remote#define#request, line 2: Vim(let):Error invoking '0:fun
ction:DbeeGetCurrentConnection' on channel 3:
Invalid channel: 3
stack traceback:
[C]: in function 'DbeeGetCurrentConnection'
...ocal/share/nvim/lazy/nvim-dbee/lua/dbee/handler/init.lua:156: in function 'get_current_connection'
...al/share/nvim/lazy/nvim-dbee/lua/dbee/ui/drawer/init.lua:62: in function 'new'
....local/share/nvim/lazy/nvim-dbee/lua/dbee/entry/init.lua:88: in function 'setup_ui'
....local/share/nvim/lazy/nvim-dbee/lua/dbee/entry/init.lua:130: in function 'open_ui'
....local/share/nvim/lazy/nvim-dbee/lua/dbee/entry/init.lua:125: in function 'toggle_ui'
...e/tuc55745/.local/share/nvim/lazy/nvim-dbee/lua/dbee.lua:24: in function 'toggle'
[string ":lua"]:1: in main chunk
if all sources are empty, there is an error
Hello,
I'm interested in having access to this driver.
When I find the time, I might attempt to implement it myself.
If creating this driver (or issue) is not something you want, please inform me.
Hi, many many thanks for this work. Have been trying it out and it looks pretty good. However i was also trying to use mongodb with it, but couldn't figure out how to use that. For example i could use db.createCollection("test_collection")
in mongosh but how would i go about it in this setup ? if you have had any tryouts or example please share.
I have the following setup (lazy.nvim).
return {
"kndndrj/nvim-dbee",
ft = "sql",
dependencies = {
"MunifTanjim/nui.nvim",
},
build = function()
require("dbee").install()
end,
config = function()
require("dbee").setup({
sources = {
require("dbee.sources").MemorySource:new({
{
id = "duck-in-memory",
name = "duck-in-memory",
type = "duck",
url = "file::memory:",
},
}),
},
})
end,
}
After Lazy sync
all is well, however when I open a .sql
file I get the following error.
Error detected while processing BufReadPost Autocommands for "*":
Error executing lua callback: ...en/.tea/neovim.io/v0.9.1/share/nvim/runtime/filetype.lua:21: Error executing lua: ...en/.tea/neovim.io/v0.9.1/share/nvim/runtime/filety
pe.lua:22: BufReadPost Autocommands for "*"..FileType Autocommands for "sql": Vim(append):[handler]: BufReadPost Autocommands for "*"..FileType Autocommands for "sql"..
function Dbee_register_connection[1]..remote#define#request, line 2: Vim(let):unable to connect to duckdb database: could not open database: IO Error: Extension "/Users
/john.allen/.duckdb/extensions/v0.8.0/osx_arm64/file.duckdb_extension" not found.
stack traceback:
[C]: in function 'nvim_cmd'
...en/.tea/neovim.io/v0.9.1/share/nvim/runtime/filetype.lua:22: in function <...en/.tea/neovim.io/v0.9.1/share/nvim/runtime/filetype.lua:21>
[C]: in function 'nvim_buf_call'
...en/.tea/neovim.io/v0.9.1/share/nvim/runtime/filetype.lua:21: in function <...en/.tea/neovim.io/v0.9.1/share/nvim/runtime/filetype.lua:10>
stack traceback:
[C]: in function 'nvim_buf_call'
...en/.tea/neovim.io/v0.9.1/share/nvim/runtime/filetype.lua:21: in function <...en/.tea/neovim.io/v0.9.1/share/nvim/runtime/filetype.lua:10>
Looks like a version mismatch.
~/.duckdb/extensions
❯ ll
.
..
17ec2ab20
v0.7.1
v0.8.1
FWIW — I didn't have v0.8.1 installed prior to installing dbee
. I did a brew install duckdb
after first error but current HomeBrew version seems to be v0.8.1.
I'm trying out the refactored version of dbee and everything is great! Except I can't figure out how to see the error output for failed queries :/
The result buffer just shows:
"Call execution failed after ..."
and the call log just says "state: executing_failed"
The old version of dbee used vim.notify (I think?) to display runtime errors?
Will Oracle database be supported in the future?
TODO
How to reproduce
select newid();
≤]Œ€#øÓFó¿úŸ˝KÙ∏
The saved queries are likely unique for each connection, or at least for each project. Right now it seems the scratchpad directory is global and not customizable.
I am loading the connections for each project using ENVIRONMENT variables, I would also like to save queries for each connection in a unique folder.
I eventually get this error after running queries with dbee for an extended period of time (keeping the dbee windows open).
Call execution failed after 0.005 seconds
Reason:
pq: sorry, too many clients already
This is my first time using the plugin, I find it really useful, although in my current setup (Ubuntu 22.04) for some reason some symbols are wrongly being showed (see below screenshot). Do you know what could cause this kind of issue? This is probably something related to my current font ("Source Code Pro"), can you tell me which fonts are compatible with the symbols used in the project?
I want to use sqlls smart completion.
But their configuration connection information is not compatible. I don't want to maintain two sets of roughly the same connection information.
dbee must be in square brackets
Expect to get the following connection information template
{
"connections" : [{
"id": "__master_connection_id_postgresqlpostgres__",
"page_size": 20,
"type": "postgres",
"url": "postgres://postgres:pg_pass@localhost/pg_test?sslmode=disable",
"name": "postgres-project",
"adapter": "postgres",
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "pg_pass",
"database": "pg_test",
"projectPaths": ["/Users/joe-re/src/postgres_project"]
}]
}
from translate.google
BEGIN;
UPDATE ...;
ROLLBACK;
Running just the UPDATE statement yields the expected output, e.g.
│ Rows Affected
───┼───────────────
1 │ N
however when run within the transaction block (regardless whether you finish it off with a ROLLBACK or a COMMIT) yields:
│ No Results
──┼────────────
It seems that SELECT statements still produce output when run within a transaction block, but UPDATE, INSERT and DELETE statements do not (they all produce the "No Results" output above).
I haven't tested SAVEPOINTs.
I'm trying to connect to a MySQL server available on localhost on non-standard port.
I've tried the following DSNs (all fail):
user_name:pass_word@tcp(127.0.0.1:3308)/dbname
Error 05:20:44 PM notify.error nvim-dbee mysql: invalid url: parse "user_name:pass_word@tcp(127.0.0.1:3308)/dbname": first path segment in URL cannot contain colon
Error 05:20:44 PM notify.error nvim-dbee [handler]: .../share/lazynvim/lazy/nvim-dbee/lua/dbee/handler/conn.lua:65: problem adding connection
mysql://user_name:pass_word@tcp(127.0.0.1:3308)/dbname
Error 05:23:29 PM notify.error nvim-dbee mysql: invalid url: parse "mysql://user_name:pass_word@tcp(127.0.0.1:3308)/dbname": invalid port ":3308)" after host
Error 05:23:29 PM notify.error nvim-dbee [handler]: .../share/lazynvim/lazy/nvim-dbee/lua/dbee/handler/conn.lua:65: problem adding connection
mysql://user_name:[email protected]/dbname
Error 05:24:30 PM notify.error nvim-dbee unable to connect to mysql database: default addr for network '127.0.0.1:3308' unknown
Error 05:24:30 PM notify.error nvim-dbee [handler]: .../share/lazynvim/lazy/nvim-dbee/lua/dbee/handler/conn.lua:65: problem adding connection
This is similar to the #14, but the solution posted there no longer works due to URL parsing check added since it was posted: d461eb1
Self explanatory.
Also, I know I've been creating a bunch of issues (because I love this plugin so much and it is by far my most used plugin), so if some of these are (relatively; I don't know Go) simple and you can point me in the right direction I can submit a PR
Hi i am trying this plugin for the first time. Attempting to connect to a sqlite db in my current directory.
{
"kndndrj/nvim-dbee",
dependencies = {
"MunifTanjim/nui.nvim",
},
build = function()
-- Install tries to automatically detect the install method.
-- if it fails, try calling it with one of these parameters:
-- "curl", "wget", "bitsadmin", "go"
require("dbee").install()
end,
config = function()
require("dbee").setup({ lazy = true, debug = true })
end,
},
:w
Despite enabling logs
cat ~/.cache/nvim/dbee/dbee.log
cat: /home/kay/.cache/nvim/dbee/dbee.log: No such file or directory
NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3
Full error message:
Error 08:41:07 notify.error nvim-dbee [handler]: BufWriteCmd Autocommands for "<buffer=34>"..FuncUndefined Autocommands for "Dbee_register_connection"..function remote#define#FunctionBootstrap[1]..remote#host#Require[10]..29_Start_dbee, line 1: Vim(return):E475: Invalid value for argument cmd: 'dbee' is not executable
title
In my projects, I often have multiple DB connections and Dbee often picks the "wrong" one by default. It would be nice to specify the default connection, either as an environment variable or as an option to the "open/toggle" functions
Hi there!
I'm really looking forward to trying out this plugin. Also, I'm really fascinated to read through your code and see how the go-lua interop works.
When I first attempted to setup a connection to my local db, I started getting this error on startup and all subsequent execution commands seemed to fail as well.
Here is a screenshot of the error
Here is my configuration:
Packer:
use ({
"kndndrj/nvim-dbee",
requires = {
"MunifTanjim/nui.nvim",
},
build = function()
-- Install tries to automatically detect the install method.
-- if it fails, try calling it with one of these parameters:
-- "curl", "wget", "bitsadmin", "go"
require("dbee").install()
end,
run = function()
-- Install tries to automatically detect the install method.
-- if it fails, try calling it with one of these parameters:
-- "curl", "wget", "bitsadmin", "go"
require("dbee").install()
end,
})
here is my config function called from my init.vim file:
local status_ok, dbee = pcall(require, "dbee")
if not status_ok then
vim.notify("dbee not found ")
return
end
dbee.setup({
connections = {
{
name = "examplemysql",
type = "mysql",
url = "mysql://root:redacted@localhost:3306/db1",
},
}
})
Is there a mistake that I made in the config?
Thanks in advance,
~Nick
I'm really looking forward to trying out this plugin but I failed on the initial load. i get this on startup of nvim:
Failed to load `plugins.dbees`
/home/user/.config/nvim/lua/plugins/dbees.lua:4: module 'secrets' not found:
^Ino field package.preload['secrets']
cache_loader: module secrets not found
cache_loader_lib: module secrets not found
^Ino file './secrets.lua'
^Ino file '/usr/share/luajit-2.1.0-beta3/secrets.lua'
^Ino file '/usr/local/share/lua/5.1/secrets.lua'
^Ino file '/usr/local/share/lua/5.1/secrets/init.lua'
^Ino file '/usr/share/lua/5.1/secrets.lua'
^Ino file '/usr/share/lua/5.1/secrets/init.lua'
^Ino file './secrets.so'
^Ino file '/usr/local/lib/lua/5.1/secrets.so'
^Ino file '/usr/lib/lua/5.1/secrets.so'
^Ino file '/usr/local/lib/lua/5.1/loadall.so'
# stacktrace:
- ~/.config/nvim/lua/plugins/dbees.lua:4
- ~/.config/nvim/lua/lazy-bootstrap.lua:14
- lua/:1
I used the quickstart for lazy from the README:
return {
"kndndrj/nvim-dbee",
dir = require("secrets").get("dbee_path"),
dependencies = {
"MunifTanjim/nui.nvim",
},
build = function()
-- Install tries to automatically detect the install method.
-- if it fails, try calling it with one of these parameters:
-- "curl", "wget", "bitsadmin", "go"
require("dbee").install()
end,
config = function()
require("dbee").setup(--[[optional config]])
end,
}
It looks like dbee is setreg()
ing to the unnamed register, but often I will copy the result output so that I can paste it somewhere else (Slack to share with teammates, GitHub gists, etc) and I don't want to do :let @+=@"
every time :/
So there's two things:
""yaJ
would mimic the current behavior, but I could do "+yaJ
to use the selection register.Is there a short cut to be able to execute the command in the scratchpad?
In vim dad bod ui, either save works to auto exec or Leader+S. Struggling to find out how to execute the query using nvim-dbee in scratchpad
it is not documented under https://github.com/kndndrj/nvim-dbee#getting-started scratchpad
Some research needs to be done for implementation of interactive commands in results buffer.
Examples of these commands are:
TODO: investigate what works and what makes sense to progress the story
If anyone stumbles upon this issue, any help/feedback is valuable.
Add option to cancel long run query. context cancelation...
I added this plugin by lazy, but when I trying to add a new connection, it says that dbee not found
I have to do find the install path and then manually give the runnable permission and add it to the PATH, then it can work
nvim/dbee/bin
❯ ls
dbee
nvim/dbee/bin
❯ dbee
zsh: command not found: dbee
nvim/dbee/bin
❯ ./dbee
zsh: permission denied: ./dbee
nvim/dbee/bin
❯ chmod u+x dbee
nvim/dbee/bin
❯ ./dbee
^C
nvim/dbee/bin took 5s
❯ export PATH=$(pwd):$PATH
nvim/dbee/bin
❯ cd
~
❯ dbee
^C
If you are in the 'drawer' and browsing the structure and hit Enter on a table, it brings up a list of 'helpers'
Choosing a helper fails if the database name does not match the database name from the connection config. It is valid not to specify a db name in the config, but that then means you can't use any of the databases because of this issue.
I think two improvements would be:
Thanks!
With the knowledge of the DB structure nvim-dbee
has, it would be nice if it could expose it as a completion source (e.g. for nvim-cmp
), similar to https://github.com/kristijanhusak/vim-dadbod-completion
I encountered this error while trying to install the plugin:
...hare/nvim/lazy/lazy.nvim/lua/lazy/manage/task/plugin.lua:84: Vim:E154: Duplicate tag "DefaultLayout" in file /home/troysigx/.local/share/nvim/lazy/nvim-dbee/doc//dbee-reference.txt
sources = {
require("dbee.sources").MemorySource:new({
{
name = "test",
type = "sqlite",
url = "~/test.db",
},
}),
},
Error 07:21:52 notify.error nvim-dbee unable to open database file: out of memory (14)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.