Coder Social home page Coder Social logo

kndndrj / nvim-dbee Goto Github PK

View Code? Open in Web Editor NEW
697.0 7.0 48.0 1.03 MB

Interactive database client for neovim

License: GNU General Public License v3.0

Lua 50.32% Go 48.50% Shell 1.19%
neovim bee database database-client golang lua neovim-plugin nvim nvim-plugin

nvim-dbee's Introduction

Linting Status Docgen Status Backend Frontend

"Buy Me A Coffee"

Neovim DBee

Database Client for NeoVim!

Execute Your Favourite Queries From the Comfort of Your Editor!

Backend in Go!

Frontend in Lua!

Doesn't rely on CLI tools!

Get Results FAST With Under-the-hood Iterator!

Bees Love It!

Alpha Software - Expect Breaking Changes!

Screenshot

Video Introduction

If you prefer to watch a video than to browse through docs, I made a video, which you can watch here

Installation

requires nvim>=0.10

  • packer.nvim:

    use {
      "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
    }
  • 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,
    },

Platform Support

Click to expand

This project aims to be as cross-platform as possible, but there are some limitations (for example some of the go dependencies only work on certain platforms). To address this issue, the client implementations are detached from the main logic and they register themselves to dbee backend on plugin start. This allows the use of build constraints, which we use to exclued certain client implementations on certain platforms.

The CI pipeline tries building the binary for GOARCH/GOOS combinations specified in targets.json - if the builds succeed, they are stored in a remote bucket on a separate branch per run. Additionally, the install manifest gets created.

To increase cgo cross-platform support, the pipeline uses zig as a C compiler.

To check if your platform is currently supported, check out the mentioned manifest and the targets file.

Manual Binary Installation

Click to expand

The installation examples include the build/run functions, which get triggered once the plugin updates. This should be sufficient for the majority of users. If that doesn't include you, then you have a few options:

  • just install with the "go" option (this performs go build under the hood):
    require("dbee").install("go")
  • Download an already compiled binary from one of urls in the install manifest
  • go install (the install location will vary depending on your local go configuration):
    go install github.com/kndndrj/nvim-dbee/dbee@<version>
  • Clone and build
    # Clone the repository and cd into the "go subfolder"
    git clone <this_repo>
    cd <this_repo>/dbee
    # Build the binary (optional output path)
    go build [-o ~/.local/share/nvim/dbee/bin/dbee]

Configuration

You can pass an optional table parameter to setup() function.

Here are the defaults:

config.lua

Usage

Call the setup() function with an optional config parameter.

Brief reference (click to expand):
-- Open/close/toggle the UI.
require("dbee").open()
require("dbee").close()
require("dbee").toggle()
-- Run a query on the currently active connection.
require("dbee").execute(query)
-- Store the current result to file/buffer/yank-register (see "Getting Started").
require("dbee").store(format, output, opts)

The same functions are also available through the :Dbee user command.

Getting Started

Here are a few steps to quickly get started:

  • call the setup() function in your init.lua

  • Specify connections using one or more sources (reffer to this section).

  • When you restart the editor, call lua require("dbee").open() to open the UI.

  • Navigate to the drawer (tree) and use the following key-bindings to perform different actions depending on the context (the mappings can all be changed in the config):

    • All nodes:

      • Press o to toggle the tree node.
      • Press r to manually refresh the tree.
    • Connections:

      • Press cw to edit the connection
      • Press dd to delete it (if source supports saving, it's also removed from there - see more below.)
      • Press <CR> to perform an action - view history or look at helper queries. Pressing <CR> directly on the connection node will set it as the active one
    • Scratchpads:

      • Press <CR> on the new node to create a new scratchpad.
      • When you try to save it to disk (:w), the path is automatically filled for you. You can change the name to anything you want, if you save it to the suggested directory, it will load the next time you open DBee.
      • Press cw to rename the scratchpad.
      • Press dd to delete it (also from disk).
      • Pressing <CR> on an existing scratchpad in the drawer will open it in the editor pane.
    • Help:

      • Just view the key bindings.
  • Once you selected the connection and created a scratchpad, you can navigate to the editor pane (top-right by default) and start writing queries. In editor pane, you can use the following actions:

    • Highlight some text in visual mode and press BB - this will run the selected query on the active connection.
    • If you press BB in normal mode, you run the whole scratchpad on the active connection.
  • If the request was successful, the results should appear in the "result" buffer (bottom right by default). If the total number of results was lower than the page_size parameter in config (100 by default), all results should already be present. If there are more than page_size results, you can "page" through them using one of the following:

Navigation using lua script
(even if your cursor is outside the result buffer)
Description Default key mapping
(cursor should be inside result buffer)
require("dbee").api.ui.result_page_next() Go to next page L
require("dbee").api.ui.result_page_prev() Go to the previous page H
require("dbee").api.ui.result_page_last() Go to the last page E
require("dbee").api.ui.result_page_first() Go to the first page F
  • Once in the "result" buffer, you can yank the results with the following keys:

    • yaj yank current row as json (or row range in visual mode)
    • yac yank current row as CSV (or row range in visual mode)
    • yaJ to yank all rows as json
    • yaC to yank all rows as CSV
  • The current result (of the active connection) can also be saved to a file, yank-register or buffer using require("dbee").store() lua function or :Dbee store Ex command. Here are some examples:

    -- All rows as CSV to current buffer:
    require("dbee").store("csv", "buffer", { extra_arg = 0 })
    -- Results from row 2 to row 7 as json to file (index is zero based):
    require("dbee").store("json", "file", { from = 2, to = 7, extra_arg = "path/to/file.json"  })
    -- Yank the first row as table
    require("dbee").store("table", "yank", { from = 0, to = 1 })
    -- Yank the last 2 rows as CSV
    -- (negative indices are interpreted as length+1+index - same as nvim_buf_get_lines())
    -- Be aware that using negative indices requires for the
    -- iterator of the result to be drained completely, which might affect large result sets.
    require("dbee").store("csv", "yank", { from = -3, to = -1 })
  • Once you are done or you want to go back to where you were, you can call require("dbee").close().

Specifying Connections

Connection represents an instance of the database client (i.e. one database). This is how it looks like:

{
  id = "optional_identifier" -- only mandatory if you edit a file by hand. IT'S YOUR JOB TO KEEP THESE UNIQUE!
  name = "My Database",
  type = "sqlite", -- type of database driver
  url = "~/path/to/mydb.db",
}

The connections are loaded to dbee using so-called "sources". They can be added to dbee using the setup() function:

  require("dbee").setup {
    sources = {
      require("dbee.sources").MemorySource:new({
        {
          name = "...",
          type = "...",
          url = "...",
        },
        -- ...
      }),
      require("dbee.sources").EnvSource:new("DBEE_CONNECTIONS"),
      require("dbee.sources").FileSource:new(vim.fn.stdpath("cache") .. "/dbee/persistence.json"),
    },
    -- ...
  },

The above sources are just built-ins. Here is a short description of them:

  • MemorySource just loads the connections you give it as an argument.

  • EnvSource loads connection from an environment variable Just export the variable you gave to the loader and you are good to go:

      export DBEE_CONNECTIONS='[
          {
              "name": "DB from env",
              "url": "mysql://...",
              "type": "mysql"
          }
      ]'
  • FileSource loads connections from a given json file. It also supports editing and adding connections interactively

If the source supports saving and editing you can add connections manually using the "add" item in the drawer. Fill in the values and write the buffer (:w) to save the connection. By default, this will save the connection to the global connections file and will persist over restarts (because default FileSource supports saving)

Another option is to use "edit" item in the tree and just edit the source manually.

If you aren't satisfied with the default capabilities, you can implement your own source. You just need to fill the Source interface and pass it to config at setup (:h dbee.sources).

Secrets

If you don't want to have secrets laying around your disk in plain text, you can use the special placeholders in connection strings (this works using any method for specifying connections).

Each connection parameter is passed through go templating engine, which has two available functions:

  • env for retrieving environment variables and
  • exec for evaluating shell commands.

The template syntax for functions is the following: {{ <func> "<param>" }}. If you are dealing with json, you need to escape double quotes, so it's sometimes better to use backticks instead ({{ <func> `<param>` }}).

Example:

Using the DBEE_CONNECTIONS environment variable for specifying connections and exporting secrets to environment:

# Define connections
export DBEE_CONNECTIONS='[
    {
        "name": "{{ exec `echo Hidden Database` }}",
        "url": "postgres://{{ env \"SECRET_DB_USER\" }}:{{ env `SECRET_DB_PASS` }}@localhost:5432/{{ env `SECRET_DB_NAME` }}?sslmode=disable",
        "type": "postgres"
    }
]'

# Export secrets
export SECRET_DB_NAME="secretdb"
export SECRET_DB_USER="secretuser"
export SECRET_DB_PASS="secretpass"

If you start neovim in the same shell, this will evaluate to the following connection:

{ {
  name = "Hidden Database",
  url = "postgres://secretuser:secretpass@localhost:5432/secretdb?sslmode=disable",
  type = "postgres",
} }

API

Dbee comes with it's own API interface. It is split into two parts:

  • core (interacting with core of the plugin),
  • ui (interacting with ui of the plugin).

You can access it like this:

require("dbee").api.core.some_func()
require("dbee").api.ui.some_func()

Extensions

Development

Reffer to ARCHITECTURE.md for a brief overview of the architecture.

nvim-dbee's People

Contributors

33kk avatar actions-user avatar adament avatar dabbertorres avatar joxtacy avatar justbarnt avatar kndndrj avatar mattiasmts avatar phdah avatar przepompownia avatar stephenafamo avatar teto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nvim-dbee's Issues

unknown function: Dbee_register_connection

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
Screenshot 2023-05-14 at 10 15 05 PM

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

Can the connection configuration file be added to be compatible with sqlls?

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

Strange characters in place of symbols

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?

image

Special characters muck up the results view

See screenshot as an example:

image

The more characters like this the more the table becomes unreadable.

I think a solution would be to calculate the width that vim will need to display the values and use that as column width; instead of what I presume is just a length-of-characters-in-string function?

[bigquery] Cannot finish fetching results with BigQuery resource

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 :
bigquery-nvim-dbee-cannot-get-results.

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.

dbee not found after add the plugin by lazy

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

[Bug] Doc issue; Duplicate "DefaultLayout"

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

Dbee ui toggle throws error

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

[Help wanted] "dbee" command not found

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,
  }

Can't see error output for failed queries?

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?

Ability to set default connection

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

Some postgresql statements don't have output

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>

[Feature] Nvim Tree integration

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.

Ui interactive commands

Some research needs to be done for implementation of interactive commands in results buffer.

Examples of these commands are:

  • goto foreign key
  • delete row
  • duplicate row
  • change cell value

TODO: investigate what works and what makes sense to progress the story

If anyone stumbles upon this issue, any help/feedback is valuable.

Clickhouse Nullable columns in result window

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.

Cannot connect to MySQL

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?

Feature suggestion: Yank CSV/JSON for results

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!

How do I add connections with secure secrets?

This is kind of 3 parter:

  1. It's not clear how to add connections. I see from the help file that you can add connections from the setup config, I think that should be prominently displayed on the README because it's the first thing a new user will need to do.
  2. It would be really great if we could add connections interactively while it is running, with a user command and/or buffer local mapping on the sidebar.
  3. I don't see any way that I can configure a connection without storing the password in plain text.

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`
           }
         },

Specify ScratchPad directory for each connection

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.

Add gcloud spanner driver

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.

[postgres] too many clients already

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

DuckDB error

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.

MySQL DSN with a port

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

CSV yanks only part of the data

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.

module secrets not found

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,
}

MongoDB usage

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.

Unable to connect to sqlite db `Dbee_register_connection` 'dbee' is not executable

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,
},

image

:w

image

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

show column number on `relativenumber` options

image

Hello my options have vim.opt.relativenumber = true. How can I disable line number in dbee-drawer, dbee-call-log, dbee-result. They don't have custom buftype or filetype to customize by autocmd, they're just filename

Helper SQL should select the selected database

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:

  1. the helper - which is executed in the context of having selected a database from the drawer - should know to work on the database selected in the drawer.
  2. where a db is pre-selected in the config, it should be easier to get to it. It is still useful to show all dbs reachable with the connection, but some way to show the one pre-selected in config would be helpful. On a host with 100 databases, it would be nice not to have to search for something that's specified in config. Perhaps the selected one could simply be sorted to the top of the list?

Thanks!

Feature request: disconnect from active connection

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

[postgres] no output when executing some statements inside of transaction block

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.

Doesn't work with packer and LunarVim

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:
image
And this error when starting LunarVim (which is weird as I don't use lazy, I use packer):
image

My versions:
NVIM v0.9.5
LunarVim 1.3

Change which register is used for "yank"

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:

  1. Configure option to specify which register to use by default when yanking.
  2. Respect the register provided as part of the command sequence: ""yaJ would mimic the current behavior, but I could do "+yaJ to use the selection register.

Feature request: database helpers

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.