librelist archives

« back to archive

OR, > and other SQL comparisons

OR, > and other SQL comparisons

From:
choonkeat
Date:
2010-01-20 @ 13:38
Hi friendlyorm,

I know Friendly is based on Sequel (not too familiar), and Sequel can
perform pretty much any SQL. My question is, how do I get to them via my
Friendly model? I pretty much only know how to use the #all and #scope, and
they seem to only accept 1 Hash object as parameter (AND condition all the
way?).

So for example

class Person
  include Friendly::Document
  attribute :hidden, Friendly::Boolean
  indexes :hidden
end

How do I retrieve all Person entries with "hidden => false" OR "created_at >
10.minutes.ago"? In fact.. how do I do a greater/smaller comparison?
Currently I'm doing BETWEEN with range comparison, e.g. Contest.all(:score
=> 0..100)


Thanks
--
choonkeat

Re: [friendly] OR, > and other SQL comparisons

From:
James Golick
Date:
2010-01-20 @ 16:43
Basically, the idea is that you can't. Currently, it does work, but at a
later date, these queries may be unsupported.

The idea of friendly is that only fast queries are possible. Disjunction is
slow, and with enough data, it won't be practical unless you keep throwing
hardware at it. It's also not possible to use memcached to satisfy such
queries.

If you're going to have a small amount of data, I'd recommend just using a
normal mysql table for those kinds of queries. Otherwise, denormalization is
your friend.

Hope that helps,

 -J.

On Wed, Jan 20, 2010 at 5:38 AM, choonkeat <choonkeat@gmail.com> wrote:

> Hi friendlyorm,
>
> I know Friendly is based on Sequel (not too familiar), and Sequel can
> perform pretty much any SQL. My question is, how do I get to them via my
> Friendly model? I pretty much only know how to use the #all and #scope, and
> they seem to only accept 1 Hash object as parameter (AND condition all the
> way?).
>
> So for example
>
> class Person
>   include Friendly::Document
>   attribute :hidden, Friendly::Boolean
>   indexes :hidden
> end
>
> How do I retrieve all Person entries with "hidden => false" OR "created_at
> > 10.minutes.ago"? In fact.. how do I do a greater/smaller comparison?
> Currently I'm doing BETWEEN with range comparison, e.g. Contest.all(:score
> => 0..100)
>
>
> Thanks
> --
> choonkeat
>
>
>