Getting started with Sequel in Rails

I suppose one of the reasons why sequel in rail isn’t as popular as Active Record is that, that ORM decision is made for you out of the box with rails. I suppose, in the end, it doesn’t matter too much. BaseCamp seems to be doing just fine with ActiveRecord, and is immensely profitable, given its costs and scale, as are many other organisations using it. But if you want to push the boundaries of performance, then perhaps you can try Sequel. I would even bodly venture to say, if all the hype regarding Sequel is genuine and to be believed, and if a magical wand could be waved, it would replace ActiveRecord.

The problem is that there is a little bit of a learning curve, and it is a little bit fiddly if you’re not familiar with it. Something that would take you 3 minutes with Rails and ActiveRecord out of the box might take you 4 hours configuring and try to make it work.

Hopefully this will spare you some of that ordeal.

  1. Go to sequel_rails. Follow the set up instructions there.
  2. Run a rails scaffold: rails g Organisation registration_no name
  3. Run rake db:create
  4. Run rake db:migrate
  5. Go to your models/organisation.rb file add add in this magically line:
class Organisation < Sequel::Model
  Sequel::Model.plugin :active_model ## <=== Add in that magical line
end

Now hopefully everything will just work out of the box.

You’ve done your Sequel hello world. Now go forth and make ye apps for all nations.

Written on December 19, 2019