Mike Slinn
Mike Slinn

Database Frameworks for Sinatra

Published 2023-02-01. Last modified 2023-02-22.
Time to read: 3 minutes.

This page is part of the ruby collection, categorized under Ruby, Sinatra.

I want to build a web project using Ruby, Sinatra and a database. Ruby on Rails is not an appropriate web framework for my project, but Sinatra seems about right. Choosing a database layer, however, has proven to be problematic.

At first, I found code examples for Sinatra with DataMapper. I liked DataMapper a lot. Documentation was well done. The code examples worked, or could easily be made to work. Lots of examples can be found.

Then I learned that DataMapper had been abandoned 12 years ago in favor of Ruby Object Mapper (ROM). The last DataMapper version was v1.2.0, released on October 13, 2011.

Second System Effect

Supposedly, ROM was originally going to be DataMapper version 2, but actually ROM is a completely different user experience. This seems to be a classic example of the second system effect.

Worse, the syntax changes so much even in recent years, older ROM projects no longer work. I could not find information about upgrading projects for any version upgrade.

ROM has very few learning resources, for example, there are no books on ROM. None of the few example projects I could find worked any more – if they ever did work.

Then the coup de grĂ¢ce – StackOverflow queries to date:

ROM seems like a failed project. Too bad. Technically, it looks good. Unless significant resources were applied to overcome the issues I mention, however, I think that using ROM on a project would be an unnecessary liability.

Two Contenders

The two most popular contenders for a Sinatra ORM are ActiveRecord (best known with Ruby on Rails), and Sequel. I found the following comparison infographic on the Hanami Mastery website. I am not really interested in Hanami, since it competes with Sinatra.

Sinatra ActiveRecord

Seems that using ActiveRecord with Sinatra is a common occurance. The GitHub project for sinatra-activerecord was originally written by Blake Mizerany, the author of Sinatra. The project ships with two complete demonstration projects, one for sqlite and one for postgres.

I wrote up my experience with sinatra-activerecord separately.

Sequel for Sinatra

Sequel is another popular ORM for Ruby and Sinatra. I was impressed by the excellent documentation in the README. User-centrinc product exposition ... so rare in F/OSS!

About the Author

I, Mike Slinn, have been working with Ruby a long time now. Back in 2005 I was the product marketing manager at CodeGear (the company was formerly known as Borland) for their https://www.infoq.com/news/2007/05/codegear-ror-ide/ 3rd Rail IDE. 3rd Rail supported Ruby, and Ruby on Rails, at launch.

In 2006, I co-chaired the Silicon Valley Ruby Conference, on behalf of SD Forum in Silicon Valley. As you can see, I have the t-shirt. I was sole chairman of the 2007 Silicon Valley Ruby Conference.

Several court cases have come my way over the years in my capacity as a software expert witness. The court cases featured questions about IP misappropriation for Ruby on Rails programs. You can read about my experience as a software expert if that interests you.

I currently enjoy writing Jekyll plugins in Ruby for this website and others, and Ruby utilities.