« CherryPy 3 optimizationApologies to you blogspot users »

The Fourth Way

06/28/06

Permalink 09:25:43 am, by admin Email , 365 words   English (US)
Categories: IT, Python, Dejavu

The Fourth Way

Ted Neward has written a good discussion of Object-Relational Mapper concerns. I'd like to react to, and associate, a couple of points he makes, seemingly unrelatedly:

...we typically end up with one of Query-By-Example (QBE), Query-By-API (QBA), or Query-By-Language (QBL) approaches.

A QBE approach states that you fill out an object template of the type of object you're looking for...
a "Query-By-API" approach, in which queries are constructed by Query objects...
a "Query-By-Language" approach, in which a new language, similar to SQL but "better" somehow, is written...

and

Several possible solutions present themselves...

5. Integration of relational concepts into the languages. Developers simply accept that this is a problem that should be solved by the language, not by a library or framework...bring relational concepts (which, at heart, are set-based) into mainstream programming languages, making it easier to bridge the gap between "sets" and "objects"...[such as] direct integration into traditional O-O languages, such as the LINQ project from Microsoft...

I propose (and implemented in Dejavu) a fourth approach from QBE, QBA, and QBL. Rather than build a DSL on top of a programming language (as QBL does), use the language instead. Rather than change the programming language by introducing relational syntax (as LINQ does), use the language instead. In Dejavu, you write plain old Python functions which take an object and return True or False. Iterate over a collection of objects and it works as a filter. Pass it to the storage backend and it is translated into SQL for you. Most commonly, you pass it to the library and it does both for you: iterates over its in-memory cache of objects and merges in new objects, queried from storage. Let's call it... "query". It's not "by" anything. It has an infinitesimal learning curve. LINQ is, in essence, shoehorning higher-order functions into its various target languages in a very limited domain. Why not use a programming language that has real HOF's?

4 comments

Comment from: Todd Blanchard [Visitor] · http://www.blackbagops.net

This is what GLORP does in Smalltalk. You use evaluation blocks to do selects. For instance:

db select: BlogEntry where: [:ea | ea date > Time oneWeekAgo]

The where block gets invoked to a SQLMessageLogger records what messages were sent to it and translates those into SQL.

Definitely a nice thing to have.

08/22/06 @ 23:44
Comment from: fumanchu [Member] Email

Very cool; the abstract and "How GLORP works" documents are almost word-for-word descriptions of Dejavu. Almost. ;) Unfortunately, it looks like there are a lot of open issues but no work done since 2005.

08/23/06 @ 10:24
Comment from: Todd Blanchard [Visitor] · http://www.blackbagops.net

Work stalled for about a year. A lot has been going on lately on the glorp mailing list. I've just checked it out again and a lot of progress has been made. Still some holes (inheritance isn't done) but its a lot easier to use than it was a couple years ago.

08/26/06 @ 19:41
Comment from: Wade [Visitor] · http://yceran.org/

This is the sort of thing I've been doing with a PHP scalability layer. At core, it turns MySQL into an OODBMS for PHP objects. However, the layer is thin. The object fields are the database columns, for instance, and filtering is fairly primitive. OTOH, the collection objects do a lot in the background - you just use a simple next() method.

Other benefits include being able to store different objects in different MySQL server and I'm working towards partioning objects between multiple databases, too.

11/23/06 @ 16:40

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.

Please enter the phrase "I am a real human." in the textbox above.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
October 2017
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

Search

The requested Blog doesn't exist any more!

XML Feeds

multiple blogs