On Monday, October 1, 2012 12:35:36 PM UTC-7, David Lee wrote:

> Hi,
>
> I want to programmatically translate a mongo-like query hash to a Sequel 
> Expression to pass to Dataset#where.
>
> The input would be something like: db[:people].custom_where(age: {lt: 30})
>
> I can think of translating the above into: db[:people].where 
> {__send__(:age).__send__(:<, 30)}
>
> Is there a cleaner way to do this? Maybe someone already wrote a plugin?
>
 
I'm assuming you don't just want to do:

  db[:people].where{age < 30}

because you don't know you want to use the column age or the value 30 until 
runtime.

 You could just create the expression object directly:

  db[:people].where(Sequel::SQL::BooleanExpression.new(:<, :age, 30))

Virtual rows also have support in recent versions:

 db[:people].where{self.<(:age, 30)}

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/-/n_rZTEciZpgJ.
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