On Tuesday, May 15, 2012 9:23:07 AM UTC-7, Sean Redmond wrote:
>
> I'm new to Sequel and newish to Ruby (but coming with a lot of experience 
> in, say, Python) and I'm looking for Sequel tutorials or examples that 
> don't skip a lot of steps.  Most of what I'm finding kind of jumps over 
> everything to the punch line and when I try to recreate the example I can't 
> get it to work. I'm trying to figure out things like: If I have a table 
> with people's names how to I extend Sequel::Model to add a method that will 
> return all the people whose last names begin with a specific letter. 


If you haven't read the documentation on 
http://sequel.rubyforge.org/documentation.html, I would start there first.  
Unfortunately, I don't think there is much in the way of tutorial 
documentation for Sequel.  Most of it was written by me, and I'm not very 
good at looking at Sequel from the eyes of a new user.  I certainly would 
be willing to help anyone who was interested in writing such documentation, 
and including such documentation with Sequel.

To answer your specific question:

  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('E')

Different things in play here:

1) Creating a model subclass for the table with the people's names.
2) Using Model.dataset_module which creates an anonymous module that the 
model's dataset is extended with
3) Using Dataset#where and Symbol#ilike to create a filter that limits the 
rows to the ones with the given last initial.
4) Using Dataset#all to return all of those rows.

Feel free to ask questions here or join the #sequel channeel on Freenode 
IRC.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/4x5J2ly1YxAJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to