or go to full-text search page →

Search

Search IconIcon to open search

Query Databases in Neovim (DBUI)

Last updatedUpdated: by Simon Späti · CreatedCreated: · 4 min read · evergreen Note status Evergreen. Own words, refined over time. Still grows. Estimated from edit history · 17 sessions over 2 years · 674 words · How my notes grow Recent changes 3 months ago +255 / −12 words 4 months ago +67 / −4 words 5 months ago +1 / −3 words 5 months ago +9 / −0 words 8 months ago +0 / −2 words 8 months ago +127 / −1 words 10 months ago +7 / −0 words last year +38 / −0 words last year +12 / −0 words last year +9 / −7 words last year +19 / −0 words 2 years ago +115 / −0 words 2 years ago +3 / −0 words 2 years ago +14 / −0 words 3 years ago +2 / −0 words 3 years ago published · 6 words 3 years ago published · 6 words

Compared to other SQL IDEs, I like using vim motions and Neovim for querying and copy the data in a new buffer. There’s two plugins that make this possibel:

# How that Looks

Some examples of how that looks like in practice.

# Tmux with Dadbod-UI (and dbt)

Dadbod-UI in action with Neovim and tmux:

See more at My Setup Images All in One (Tmux and Neovim)

# General Workflow Video

asciicast

# Example with DuckDB from HTTPS CSV

Dadbod in Neovim to query any table or database within the terminal.

See the autocompletion that is activated and show penguins as suggestion as it’s an existing table. This also works for columns if setup correctly, see below Setup below.

Even DuckDB CLI in the Terminal has autocomplete 🤯

See below image with same example as above in nvim:

# Features

# Supported DBs

As of 2025-02-23, supports a modern array of backends, including NoSQL databases:
- Big Query
- ClickHouse: clickhouse://[<host>[:port]]/[<database>]
- Details see
- DuckDB: duckdb:/Users/sspaeti/Documents/duckdbs/playground-v1-1-1.duckdb
- Impala
- jq
- MongoDB
- MySQL
- MariaDB
- Oracle
- osquery
- PostgreSQL: postgresql:///foobar
- Presto
- Redis
- Snowflake
- SQL Server
- SQLite: sqlite:myfile.sqlite3 select count(*) from widgets
- Your own easily implemented adapter

  • Easily configurable based on a project directory (as seen in rails.vim, for example), rather than just globally or in a per-file modeline
  • For those that just can’t live without some piece of dbext functionality, the option g:dadbod_manage_dbext is provided to force dbext to use Dadbod’s default database.

# Connect Databases

# DuckDB

1
duckdb:/Users/sspaeti/Documents/duckdbs/playground-v1-1-1.duckdb

My configs in database.lua:

1
2
3
4
5
      vim.g.dbs = {
        local_postgres_sspaeti = 'postgres://postgres@localhost:5432/sspaeti',
        duckdb_memory = 'duckdb:',
        duckdb_file = 'duckdb:///tmp/analytics.duckdb',
      }

In Action:
asciicast

# ClickHouse and Encode Password

If passwords contain speecial characters such as @ you need to encode it for it to work.

Connection string format:
clickhouse://user:password@host/database?secure

Example - for specific database
clickhouse://default:mypass@myhost.us-east-1.aws.clickhouse.cloud/staging?secure

Example - for all databases
clickhouse://default:mypass@myhost.us-east-1.aws.clickhouse.cloud?secure

  • ?secure is required for ClickHouse Cloud (maps to --secure on the CLI)
  • Requires clickhouse-client (or clickhouse client) installed locally
  • If passwords contain special characters like @, you need to URL-encode them:
Character Encoded
@ %40
# %23
? %3F
/ %2F
% %25

Quick way to get the encoded password:

1
python3 -c "import urllib.parse; print(urllib.parse.quote('YOUR_RAW_PASSWORD', safe=''))"

# How to Setup

The best way to setup is checking my dotfiles at database.lua or TJ DeVries step by step video, including autocomplete with LSP at Vim Dadbod - My Favorite SQL Plugin:

My config from above:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
return {
  {
    'kristijanhusak/vim-dadbod-ui',
    dependencies = {
      { 'tpope/vim-dadbod',                     lazy = true },
      { 'kristijanhusak/vim-dadbod-completion', ft = { 'sql', 'mysql' }, lazy = true }, -- Optional
    },
    cmd = {
      'DBUI',
      'DBUIToggle',
      'DBUIAddConnection',
      'DBUIFindBuffer',
    },
    init = function()
      -- Your DBUI configuration
      vim.g.db_ui_use_nerd_fonts = 1
    end,
  },
  { "kristijanhusak/vim-dadbod-completion", event = "VeryLazy" },
  -- Database
  {
    "tpope/vim-dadbod",
    lazy = true,
    dependencies = {
      "kristijanhusak/vim-dadbod-ui",
      "kristijanhusak/vim-dadbod-completion",
    },
    event = "VeryLazy",
    config = function()
      -- Database connections
      vim.g.dbs = {
        local_postgres_postgres = 'postgres://postgres@localhost:5432/postgres',
        duckdb_memory = 'duckdb:',
        duckdb_file = 'duckdb:///home/sspaeti/Documents/sandbox/duckdbs/default-nvim.duckdb',
      }
    end,
  },
}

Autocompletion

Note that autocompletion is a seperate plugin called kristijanhusak/vim-dadbod-completion

# Alternatives SQL Clients in the Terminal

# Futher Reads


Origin:
References: SQL IDEs