How To Clear A Sqlite Database With The Sequel Gem

Mar 3, 2015

I’ve been playing with a new Sinatra app. While I am building it out, I am getting back to basics. I’m only adding what I need as I need it. I really have no preconceptions of what I am building. It’s a journaling app, and I am just starting with a big ‘ol textarea.

Keeping with simplicity, my database is super simple. I am just using sqlite and accessing it via the Sequel Rubygem.

While putting things together, I had some crappy data I wanted to clear out, but didn’t want to write some method to reset the database or setup environments yet. Turns out it’s pretty simple with Sequel.

With a sqlite database called journal and a table called entries, in a terminal, I just run

sequel sqlite://journal.db

This drops me into an irb session with DB setup as my database.

Sequel implements a drop_table method

DB.drop_table(:entries)

Now I have my clean database.