Rubyにおける軽量なデータベースツールキットとして、なかなかお手軽なSequelですが、実際に使うにあたっていくつか悩んだポイントがあったので、備忘録としてその解決法をメモしておきます。 なお、この記事はRuby 1.9.1p378とSequel 3.8.0の組み合わせを対象として書いています。 モデルの定義前にDB接続をしたくない SequelにもActiveRecordパターンに基づいたモデルの仕組みが用意されていますが、「モデルを定義した時点でデータベースへの接続が存在していなければならない」という制約があります。 つまり、 require 'sequel' Sequel.connect('sqlite://test.db') class User < Sequel::Model; end p User.all は動きますが、 require 'sequel' class User