sponsor Vim development Vim logo Vim Book Ad

dadbod.vim : Modern database interface for Vim

 script karma  Rating 326/112, Downloaded by 2300  Comments, bugs, improvements  Vim wiki

created by
Tim Pope
script type
Dadbod is a Vim plugin for interacting with databases.  It's a more modern take on dbext.vim (vimscript #356), improving on it on the following ways:

* Connections are specified with a single URL, rather than prompting you for 14 separate variables
* All interaction is through invoking :DB, not 53 different commands and 35 different maps (omitting many of the more esoteric features, of course)
* Supports a modern array of backends, including NoSQL databases:
  - MongoDB
  - MySQL
  - PostgreSQL
  - Redis
  - Sqlite
  - Your own easily implemented adapter
* Easily configurable based on a project directory (as seen in rails.vim (vimscript #1567), for example), rather than just globally or in a per-file modeline

## Usage

The :DB command has a few different usages.  All forms accept a URL as the first parameter, which can be omitted if a default is configured or provided by a plugin.

Omit further arguments to spawn an interactive console (like `psql` or `redis-cli`).

   :DB postgresql:///foobar
   :DB redis:

If additional arguments are provided, they are interpreted as a query string to pass to the database.  Results are displayed in a preview window.

    :DB sqlite:myfile.sqlite3 select count(*) from widgets
    :DB redis:/// CLIENT LIST

Give a range to run part or all of the current buffer as a query.

    :%DB mysql://root@localhost/bazquux

Use `<` to pass in a filename.

    :DB mongo:///test < big_query.js

There's also a special assignment syntax for saving a URL to a Vim variable for later use.

    :DB g:prod = postgres://user:pass@db.example.com/production_database
    :DB g:prod drop table users

A few additonal URL like formats are accepted for interop:

* `:DB jdbc:postgresql://...`
* `:DB dbext:profile_name`
* `:DB dbext:type=PGSQL:host=...`
* `:DB $DATABASE_URL` (with optional dotenv.vim (vimscript #5176) support)

Plugins can provide their own URL handlers as well.  For example, heroku.vim (vimscript #4915) provides support for `heroku:appname` style URLs.
install details
Extract in ~/.vim (~\vimfiles on Windows). Or use https://tpope.io/vim/dadbod.git with your favorite package manager.

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
dadbod.zip 1.4 2021-08-23 7.0 Tim Pope Fix issue passing password to redis-cli.
Fix error calling bufnr() on older Vim.
dadbod.zip 1.3 2021-05-14 7.0 Tim Pope Add ClickHouse adapter.
Add impala adapter.
Add jq adapter.
Add osquery adapter.
Add Presto adapter.
Support arbitrary MongoDB parameters, including authSource= and ssl=.
Support protocol=, login-path=, and ssl-*= for MySQL.
Support encrypt= and trustServerCertificate= for SQL server.
Support tab completion for SQL server.
Support command modifiers like :tab.
Support prefix to query for range selection (e.g., :%DB EXPLAIN).
Provide gq map to close results window.
Bug fixes.
dadbod.zip 1.2 2018-04-25 7.0 Tim Pope Support SQL Server.
Support Oracle.
Provide automatic management of dbext configuration.
Fix tab completion issues.
Minor bug fixes.
dadbod.zip 1.1 2018-03-17 7.0 Tim Pope Rename to Dadbod.
Fix issue with screen failing to redraw.
Fix various issues with shell execution.
Rearrange psql arguments to avoid warning.
Support SSL for MongoDB.
Support custom port in dbext wrapper.
db.zip 1.0 2018-03-08 7.0 Tim Pope Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
Vim at Github