how to build up the library..

Russel Winder russel at russel.org.uk
Fri Oct 7 00:26:30 PDT 2011


On Fri, 2011-10-07 at 08:49 +0200, Jacob Carlborg wrote:
[ . . . ]
> I think it's important to support the range interface (or if it's 
> simpler, the array interface). I think ActiveRecord has a good high 
> level API which allows to lazily evaluate SQL queries.
> 
> persons = Person.all # no query is performed here
> persons = persons.where("name = 'Joe'") # or here
> 
> persons.each do |p| # The actual query is performed here
>      # do something with each Person
> end
> 
> I don't think it would be strange to see something like this:
> 
> Person.where("age > 10").map{ |p| p.name } # using "map" on an SQL query

Not just Ruby an Rails with ActiveRecord.  Groovy/Grails/GORM does what
is basically the same.  Python cannot do the same in the same way Ruby
and Groovy can, but it has it equivalent (augmented with SQLAlchemy).
Basically it comes down to constructing dynamic queries using the
dynamic and MOP nature of the languages.  The crucial keyword here is
Builder.  The trick is that what looks like function call is actually
interpreted via the builder/MOP as the construction of a data structure,
which then creates the query on demand -- with template placeholder
filling as required.

Does D have the reflection capabilities to do this in any way, shape or
form similar tp the way the dynamic languages do it?

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20111007/2d4f55d3/attachment.pgp>


More information about the Digitalmars-d mailing list