Hi Eliot,

> Am 05.01.2015 um 16:59 schrieb Eliot Miranda <eliot.mira...@gmail.com>:
> 
> Hi Norbert,
> 
>     this reminds me of something IIRC that Alan Knight did in TopLink, a 
> commercial OR mapping tool.  Alan allowed one to write queries in 
> conventional Smalltalk such as 
> 
>     db select: [:obj| obj name = 'foo' or: [obj feature isSomething]]
> 
> but under the covers compiling this block into a query that the database 
> could execute by evaluating the block once, passing in a "compiling" object 
> that implements doesNotUnderstand: to catch the messages sent in the block.
> 
> That technique could work in this context and avoid introducing the (excuse 
> me for saying, /horrible/) tuple syntax.
> 
IIRC I used that in Glorp as well (which is the open source successor of 
TopLink, right?)

We have that, too. It is called MongoQueries and has been done by Nicholas 
Petton. For basic usage like your example above it works perfectly. But if it 
comes to special nested accessors or complex queries you end up having problems 
really quick. I think with a little love the MongoQueries package can easily be 
extended to support a fair amount of use cases. 
You are right, the nested dictionaries are awful but those smalltalk DSL 
mapping queries are really restricted and hard to make them powerful. So it is 
again the choice between beelzebub and the devil (as we say).

Norbert
> Eliot (phone)
> 
> On Jan 5, 2015, at 4:41 AM, Norbert Hartl <norb...@hartl.name> wrote:
> 
>> 
>>> Am 05.01.2015 um 04:59 schrieb Yanni Chiu <ya...@rogers.com>:
>>> 
>>> 
>>> On Jan 4, 2015, at 4:38 AM, Norbert Hartl <norb...@hartl.name> wrote:
>>> 
>>>> someCollection select: { 
>>>>   '$or' -> { 
>>>>       { 'name' -> { 
>>>>           '$regex' -> 'test' . 
>>>>           '$options' -> 'i' } asDictionary } asDictionary.
>>>>       { 'description' -> { 
>>>>           '$regex' -> 'test' . 
>>>>           '$options' -> 'i' } asDictionary } asDictionary
>>>>   } 
>>>> } asDictionary
>>> 
>>> That worked. I was close, but I was using $or: instead of $or, and I was 
>>> missing one level of asDictionary.
>>> 
>>> Just for the archive, there’s one more query I needed, which was to find an 
>>> object based on it’s object id. I ended up using:
>>> 
>>>   voyageId := Integer readFrom: (request at: #voyageId) base: 16.
>>>   someModel := SomeModel selectOne: { '_id' -> (OID value: voyageId) } 
>>> asDictionary.
>>> 
>>> This is a web app using Teapot and Mustache, so I write the voyageId out 
>>> using:
>>> 
>>>   self voyageId value printStringHex
>> 
>> Sounds cool. If you have anything to publish I'm interested what you've 
>> done. Especially if you have some nice tricks doing form handling in teapot.
>> 
>> Btw. for the archive. A common use case I encounter is to query objects that 
>> are being referenced by another object. It works like this
>> 
>> AnyClass>>#referencedBy: anObject
>>   ^ AnyClass selectMany: {
>>       'reference.__id' -> anObject voyageId } asDictionary
>> 
>> Norbert
>> 
>> 
> 


Reply via email to