Xemptuous / sqlua.nvim

A SQL IDE and UI for NeoVim written in Lua. Inspired by vim-dadbod vim-dadbod-ui.
Apache License 2.0
47 stars 0 forks source link

Trying to get this setup in LazyVim and cant seem to get anything to start right #23

Open derekbunch opened 1 week ago

derekbunch commented 1 week ago

when starting with nvim '+SQLua' i get the following error message

Error detected while processing command line:
Error executing Lua callback: .../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: Vim:Error executing Lua callback: ...ocal/share/nvim/lazy/sqlua.nvim/lua/sqlua/connection.lua:20: attempt to index local 'con' (a nil value)
stack traceback:
        ...ocal/share/nvim/lazy/sqlua.nvim/lua/sqlua/connection.lua:20: in function 'setup'
        ...nch/.local/share/nvim/lazy/sqlua.nvim/lua/sqlua/init.lua:48: in function <...nch/.local/share/nvim/lazy/sqlua.nvim/lua/sqlua/init.lua:40>
        [C]: in function 'cmd'
        .../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: in function <.../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:16>
stack traceback:
        [C]: in function 'cmd'
        .../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: in function <.../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:16>

when trying to start it using :SQLua in an already open session, i get the following error message

Error executing Lua callback: .../.local/share/nvim/lazy/sqlua.nvim/lua/sqlua/ui.lua:1478: Invalid buffer id: 1
stack traceback:
    [C]: in function 'nvim_buf_delete'
    .../.local/share/nvim/lazy/sqlua.nvim/lua/sqlua/ui.lua:1478: in function 'setup'
    .../.local/share/nvim/lazy/sqlua.nvim/lua/sqlua/init.lua:41: in function <.../.local/share/nvim/lazy/sqlua.nvim/lua/sqlua/init.lua:40>

I've tried starting with:

Not entirely sure what to try to get it to work.

I have defined some connections in the connections.json to see if maybe that was the issue but same error messages are the result.

sqlua.lua

return {
  "xemptuous/sqlua.nvim",
  lazy = true,
  cmd = "SQLua",
  config = function()
    require("sqlua").setup()
  end,
}

Neovim --version

❯nvim --version
NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713773202
Run "nvim -V1 -v" for more info

LazyVim version

    ● LazyVim 4.03ms  start
        dir     ~/.local/share/nvim/lazy/LazyVim
        url     https://github.com/LazyVim/LazyVim
        version 12.24.0
        tag     stable
        branch  main
        commit  8ddc6f9
        readme  README.md
        help    |LazyVim.txt|

      ✔ [task] log 834.56ms

SQLua version

    ● sqlua.nvim 4.58ms  SQLua
        dir    ~/.local/share/nvim/lazy/sqlua.nvim
        url    https://github.com/xemptuous/sqlua.nvim
        branch master
        commit 0fe0b7e
        readme README.md
        cmd     SQLua 

      ✔ [task] log 198.71ms

If there is any other information i can provide, please let me know!

Xemptuous commented 1 week ago

As for the first error, It looks like it's about being unable to read the connections properly, specifically in terms of choosing the right DBMS based on the url string.

connections.json should be located in the sqlua folder, which is in the standard nvim data folder (usually ~/.local/share/nvim/sqlua/connections.json) and should be a json array like this:

[
  {
    "url": "mysql://admin:password@localhost/mydb",
    "name": "mydb-con"
  },
  {
    "url": "postgres://user@127.0.0.1:5432/public",
    "name": "psql-db"
  }
]

Url should be something like: dbms://user:pass@host:port/dbname With dbms being one of snowflake, mariadb, mysql, or postgres

Can you post an example of your connections.json with sensitive info removed?

derekbunch commented 1 week ago
[
  {
    "url": "postgres://postgres:x@0.0.0.0:5432/xxxx?sslmode=disable",
    "name": "xxxx local"
  },
  {
    "url": "snowflake",
    "name": "snowflake"
  }
]

ive tried the same postgres connection string with vimdadbod and tableplus and it worked in each of them

Xemptuous commented 6 days ago

I'm having a hard time reproducting the same error, although I did produce another.

It looks like having a space in the connection name throws some errors all around when trying to interact, as it uses that name to make the dir, check fs, and other things. Try renaming it without whitespace to see if that helps. I'm gonna start working on a PR for that to allow spaces.

As for the initial issue, I'm not entirely sure why it's happening. Are you on Windows or MacOS by any chance? The only thing the code does by that point is reading the connections.json file, doing a find on ://, grabbing the dbms name from before that match, and returning an object based on the name of the dbms matched.

derekbunch commented 4 days ago

I am on MacOS.

and i did try replacing the space with an underscore and do still see the same error. I will try to take a look at the code and see if i can narrow down where the issue is occurring or what might be happening.

derekbunch commented 4 days ago

so i went into the code and the line that is initially giving me issues is ui.lua #1447

    vim.api.nvim_buf_delete(1, {})

i commented this line and i am able to get the UI to load.

however, when i try to open a connection to the database, i get this error:

Error executing vim.schedule lua callback: ...ch/.local/share/nvim/lazy/sqlua.nvim/lua/sqlua/files.lua:71: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
    [C]: in function 'pairs'
    ...ch/.local/share/nvim/lazy/sqlua.nvim/lua/sqlua/files.lua:71: in function 'setup'
    ...bunch/.local/share/nvim/lazy/sqlua.nvim/lua/sqlua/ui.lua:747: in function 'addConnection'
    ...share/nvim/lazy/sqlua.nvim/lua/sqlua/connectors/base.lua:395: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>

ive done some debugging and it looks like this error comes from the fact that my .../.local/share/nvim/sqlua/db_name folder is empty.

Is the expectation that i should have some config here? or that the plugin writes some files automatically here?

derekbunch commented 4 days ago

hmm, i just tried adding an empty file to my .../.local/share/nvim/sqlua/db_name folder and things seem to be working now. touch .../.local/share/nvim/sqlua/db_name/some_file

not really sure what the purpose of the buf_delete is or why files must be created in the db_name directory, but with those 2 changes, i am able to run queries against my database

Achrou commented 21 hours ago

Same problem: /.local/share/nvim/lazy/sqlua.nvim/lua/sqlua/ui.lua:1478: Invalid buffer id: 1

image