3 ms·
That's one thing I love about Gemstone/Smalltalk. In Smalltalk, you would write such a query as: (cars select: [ :car | car insurance endDate < now ]) size
by mpweiher 8y ago
That's one thing I love about Gemstone/Smalltalk.
In Smalltalk, you would write such a query as:
(cars select: [ :car | car insurance endDate < now ]) size.
(There probably is a shortcut for just counting the elements, though admittedly you have to have each car for the query).
So what Gemstone does is that when cars is a DB collection, it interprets the block and turns it into a query. So the code for iterating in-memory and the code for doing an optimized query is the same.
- vidarh 8y agoIn Ruby, using Sequel: DB[:cars].where { insurance_end_date < Time.now }.count (replacing "Time.now" with Sequel.function("NOW") if you want server side, or whatever date/time formatting function you want that'll return time/date in your desired format client side; client side it'll be evaluated once) I think most ORMs can do a reasonable job at this in languages where you have sufficient flexibility in overloading behaviour.