Am 07.10.2011, 09:26 Uhr, schrieb Russel Winder <rus...@russel.org.uk>:
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?
This has already been done in D. There is a nice library that assembles
queries at compile time and fetches results lazily into structs. The name?
Sorry, I forgot. But the author will probably show up here.