Even though I agree with @Vitor's comment saying that Vim is not meant to interact with a database, here is another solution:
Tim Pope recently released vim-dadbod that he calls "a more modern take on dbext.vim"
DB is a Vim plugin for interacting with databases.
It's a more modern take on dbext.vim, 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, for example),
rather than just globally or in a per-file modeline
From what I tested the postgresql integration works fine, given the usual quality of Pope's plugins there's a chance that it is a good solution.