DEV Community

leojpod
leojpod

Posted on • Edited on

5 1

The day I decided to learn DBext.vim

Feel free to skip over that part and head straight to the hopefully useful content here.

Almost a year and a half ago, while I was working at Repositive (a cool start-up, you should check what they do), I was convinced by mostly 2 of my colleagues to start using vim.

Soon after, I started a quest for plugins for everything! A part of that quest can be found by looking at the history of my dotfiles repo, you'll see it's a mess.

At some point during that quest, I thought of looking for a plugin that would allow me to not use things like workbench, robomongo, pgAdmin or even psql as I tend to use most after I ditched Atom for nvim. That's when I found this plugin: DBext.vim

It promised to do all I needed and then some more! awesome!

Except, I never took the time to learn it properly hence I never used it and continued to hack my way with psql. Fast-forward to today, I had to do a bunch of work on our database for my new ticket at Zeit.io (new website coming soon - in the meantime, if you need something done well give us a call!) and went on looking for the perfect nvim plugin again and ... wait a minute, I know this plugin! Yep... I knew it, it was already in my config and had been there for a while... So this time I decided to take learn how to use it properly or well enough at least that I would not need to use psql anymore and could work from my text editor.

Diving in

The repo's README.md sounded a good place as any to start and that 's where I saw that DBext.vim provided a nice tutorial, it might be a bit lengthy for some but in short:

  • start by setting up a connection: in my case, I wanted to connect to PSQL by default so I added this to my .vimrc
let g:dbext_default_profile_PG = 'type=PGSQL:user=postgres:passwd=:host=localhost:port=5432:dbname=@askb'
let g:dbext_default_profile = 'PG'

Enter fullscreen mode Exit fullscreen mode

Note the @askb, it means that DBext will prompt me to know which database to connect once for each buffer.

  • then learn about a few commands that are quite handy:

    • <leader>sbp: if your config isn't right this will allow you to open a quick setup guide. I used it a lot while trying things at first.
    • <leader>slt: list the tables in your database.
    • <leader>st: show table, probably one of the command I use the most. It allows you to get a really quick overview of a table. Just put your cursor over a table name, type in the mapping and voilà! (If you capitalise the t, i.e. <leader>sT, DBext will prompt you to know how many rows you'd like to see)
    • <leader>stw: Same as above but will ask you for a WHERE clause. This is sooo neat!
    • <leader>sd: Describe the table instead of listing its content, this is also pretty handy.

But most importantly the feature I like the most in all of this is that I don't need to be in a SQL or any other database script: I can run all these from anywhere, from my front-end code, from the doc, from a ticket description, ... This allows me to get a quick glance at what the db holds and to get good insights on what it holds for which tables.

EDIT: since I started writing this post, I've seen the Tim pope version of this: vim-dadbod. I haven't tried it yet, that might wait another year :D but if you've feedback about this plugin or some database recipes to share: please let me know!

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Instrument, monitor, fix: a hands-on debugging session

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️