Re:How not to structure database-backed web apps: performanc...
by vidarh on Thursday June 28, 2018 @05:56AM
(#17415480)
In 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.
In Smalltalk, you would write such a query as:
(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.