Skip to content

Instantly share code, notes, and snippets.

@silasb
Created May 18, 2012 12:19
Show Gist options
  • Select an option

  • Save silasb/2724995 to your computer and use it in GitHub Desktop.

Select an option

Save silasb/2724995 to your computer and use it in GitHub Desktop.
Sequel Model
require "sequel"
# connect to an in-memory database
DB = Sequel.sqlite
# create an items table
DB.create_table :people do
primary_key :id
String :last_name
end
peoples = DB[:people]
# populate the table
peoples.insert(:last_name => 'Bridge')
peoples.insert(:last_name => 'Snyder')
peoples.insert(:last_name => 'Frank')
class Person < Sequel::Model
dataset_module do
def with_last_initial(initial)
where(:last_name.ilike("#{initial}%")).all
end
end
end
# usage
Person.with_last_initial('B')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment