Ambition would clearly be the best, but until 1.9 supports parsetree
in some way I agree that it shouldn't go into core. If we need to pick
the best of the worst, I propose to define #| #& on hashes, and do it
this way:
Model.all({:age.gte => 65} | {:age.lt => 65, :retired => true})
Model.all({:age.lt => 65} & ({:donated => true} | {:admin => true}))
I have experimented with it, and its easy to get working.
This allows for infinite nesting, short syntax, and does not break the
old one in any way.
If you're not keen on using bitwise-operators here, this can just as
well work with defining #and #or on Hash, but then you need some extra
brackets.
Sindre
[email protected] wrote:
> Hey everyone,
>
> I've started working on prototyping a way to perform more complicated
> queries. You can find my work at [1]. Its just a hack to see how well
> it works, and is on no way final.
>
> I'm having trouble designing a way to specify this in the user-facing
> side of it. We've brainstormed a couple examples at [2], but I'm not
> happy with any of them, for various reasons. The all seem verbose and/
> or unintuitive. Thats why I'm coming here for help. Please post any
> bright ideas you might have on how we can make this workable and
> rubyish.
>
> Things to keep in mind:
>
> * It won't always be SQL. In the next few weeks, DataMapper will be
> performing all the condition-matching internally, for all adapters.
> However, it will be easy for any adapter to extend that, and write
> their own matchers using the native code.
> * There's some pretty slick shortcuts that could be done here, but I
> don't care about them now. I'd like to make the "query language" be
> pluggable, so we can add on those shortcuts. What I'm trying to come
> up with now has to be adaptable enough to cover every case, at the
> expense of prettiness. We'll worry about that part later.
> * If anyone has seen this done anywhere before, Java, Python, etc,
> link it in this thread. We could all learn from the others'
> implementations.
>
> I'm really excited about this feature, and it'll give us something no
> other ORM has, in addition to making adapter writing even simpler than
> it is now.
>
> Paul
>
> [1]
> http://github.com/paul/dm-core/tree/78dc9879d4eb8d53cbc4e8a88fee96ad89803cfc/lib/dm-core/conditions
>
> [2] http://gist.github.com/54237
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
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/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---