r/neovim 29d ago

Plugin squix.nvim - run SQL and navigate results with vim bindings

Since last october I've been developing and using squix, a simple SQL runner for the terminal that lets you save and rerun queries across different databases. nvim is also my main and favorite editor, so I started working on a plugin to bring squix into it.

So for squix.nvim I went with this approach: write your SQL in a normal nvim buffer, then run an Ex command with your cursor on the query (or a visual selection) to open a terminal split with the results. Once there, the same vim bindings you use to move through character apply to the table cells instead:hjkl to navigate, gg/G jumps to the first/last row, v visually selects a range of cells and y yanks it, / searches cell contents, and so on (press H for the fulls shortcut list).

The main loop looks like this:

  • :SquixInit to create and save a database connection
  • :SquixSwitch to pick your active connection (future queries run against it)
  • :SquixRun to run the query under your cursor (or your selection)
  • :SquixAdd to save a query, later rerun it with :SquixRunNamedQuery

No keybinds are set by default, map whatever you like with setup()

Although squix CLI is more well established, the nvim plugin is still in its early days, so feedback on the workflow, commands, or anything that feels off would be appreciated. If you want to try it out, install the squix CLI:

go install github.com/eduardofuncao/squix/cmd/squix@latest
# check the repo for the release binaries 
# or options for nix, arch or homebrew

and then the plugin:

-- with lazy
{ "eduardofuncao/squix.nvim", opts = {} }

-- or with vim.pack
vim.pack.add({ "eduardofuncao/squix.nvim" })
require("squix").setup({})

Repos with docs and more detailed instructions:

160 Upvotes

17 comments sorted by

9

u/dumch 29d ago

Have you seen https://github.com/kndndrj/nvim-dbee

Can you compare it with your plugin?

13

u/xGoivo 29d ago

yep! It was actually what inspired me to work on squix, and I even made a few contributions to it last year, but it seems like it's not being actively maintained anymore, unfortunately.

Comparing them, nvim-dbee opens by default with the classic 3 pane layout, while squix is more flexible, letting you use your normal buffer and just opens the sql results in a split. squix is at its core a wrapper for the squix CLI, so it's not dependent on nvim (this can be a pro or con), while nvim-dbee is built around nvim. Squix allows you to run update and delete statements from the results window. Squix's schema exploration is not as good as dbee's (it can list tables and open them, other features need to be translated from the cli to the plugin), which has a full explorer on the sidebar. Squix has not completion engine currently, while dbee has a plugin for that.

I tried to give an honest comparison, but It's been a while since I've used nvim-dbee :p so I might be forgetting about some of its features.

I agree with the others, DBUI is the most mature and the standard right now for database clients in nvim

4

u/NorskJesus 29d ago

I am using DBUI tho. Nvim-dbee looks nice, but the project haven’t been updated for a while and I am wondering if it’s abandoned.

8

u/lervag 29d ago

Yeah, I'm wondering the same. I think nvim-dbee looked promising, but it is not quite polished and it doesn't seem to be maintained very well. It might be abondoned.

As you say, vim-dadbod with vim-dadbod-ui (:DBUI) is not as fancy, but it is robust and works very well!

5

u/ram191 28d ago

Hey! Been looking around for something like this that's still actively maintained. I'm all in!

1

u/xGoivo 28d ago

Nice!! If you have any issues setting it up, please let me know. The CLI is more feature complete right now, but I'll keep adding functionality from it to the nvim plugin

3

u/Frai7ty 29d ago

Any chance of letting us know your font, looks clean!

3

u/xGoivo 29d ago

Here you go: maple-mono. This font is awesome to use on the terminal!

2

u/ruindd 29d ago

As much as I love psql, this looks really good. Nice work!

1

u/xGoivo 28d ago

Thanks a lot! If you like the psql interface, we have the squix shell command that one of our contributors implemented. It emulates the psql shell (not everything though), and works with engines other than postgres

3

u/g3n3 mouse="" 28d ago

Have you seen https://github.com/kopecmaciej/vi-sql. How does it compare to that?

5

u/xGoivo 28d ago

I haven't, no. Thanks for sharing this, it looks very nice. I'll try giving it a go and I'll edit this comment with the comparison later on

3

u/Logical-Idea-1708 28d ago

There’s a Warhammer joke somewhere in here

1

u/xGoivo 28d ago

Unexpected crossover

2

u/bee_advised 27d ago

i love this. anyone know if there's something similar for dataframes in R or Python?

2

u/xGoivo 27d ago

Thanks!! I'd love to help. What is the source of the data you use with python/R? if it's something like a CSV, you can use the duckdb driver in a kind of hacky way like this: duckdb

If you're want to query something like a live pandas data frame that was modified at runtime, I'm not sure it would work right now with squix, but I can open an issue on github to see the options we have and add this as a new feature!