From: Steve Tuckner Date: 2004-01-09T22:42:43+09:00 Subject: Re: Query syntax in O-R mapping (was: Database applications and OOness) A bit of background before I respond to the question of using Critera for SQL I had planned on doing a Query class just like Criteria a while before it appeared on the scene for my RubyWorld project (still unreleased). The reason I need it is that RubyWorld is based on synchronizing objects in memory with external data sources, one of which may be an SQL accessible database. I need to tell which objects in memory correspond to which objects in the data store. An intermediate query language therefore fills the bill. It can be tested against local objects and converted into SQL (or some other query language) to access objects in the remote store. For me it was just easier to use Ruby as my parser than to write my own. So Criteria needs to be looked at in the context of the general problem of filtering out objects from many different data store types and not just SQL. If you are just dealing with SQL databases, then maybe Criteria is no better than embedded SQL. Steve Tuckner P.S. I was amazed at the things released by Ryan when Criteria came out. All of them I was doing in some other fashion at the time. Of course Ryan's are released and mine will be someday.... > -----Original Message----- > From: Ryan Pavlik [mailto:rpav@mephle.com] > Sent: Friday, January 09, 2004 4:11 AM > To: ruby-talk ML > Subject: Re: Query syntax in O-R mapping (was: Database > applications and > OOness) > > > On Fri, 9 Jan 2004 13:41:44 +0900 > sera@fhwang.net (Francis Hwang) wrote: > > > > Here's my concern: Seems to me than when you have a syntax that > > looks _sort of_ like normal Ruby, but is different in all these tiny > > subtle ways, using it might involve a lot of "mental housekeeping" > > about why things work and don't work. In particular, the idea of > > teaching a moderately skilled programmer how to use Criteria is > > pretty daunting. > > Well, for me, it comes down to Criteria---albeit not perfect, > especially in the ways you mentioned---being better than embedding SQL > text into Ruby. Secondly, it's an abstraction, which means primarily > it doesn't necessarily generate SQL, which is useful (at least in > theory). > > > Is this not a problem for Criteria users? Am I just worrying too > > much? > > Of course "it's less bad" doesn't answer your question. I'd say you > only need to be especially aware of 2 things to use Criteria: > > 1) Method operators (&, |, etc) vs syntax operators (&&, ||, etc) > 2) Operator precedence > > The latter isn't really so much of an issue either, at least for > me... I tend to explicitly specify parens anyway, just because I like > the way it looks on the screen. > > This isn't to say Criteria isn't tricky. To be honest, because of the > way it wraps back into the language, there are a lot of weird things > that you can do, and a lot of things that happen "magically". I don't > think anyone has to wrap their head around the whole thing to use it, > though. (At least, I hope not, because I use it, and I don't always > see all the possibilities. ;) > > I can't come up with a better way to integrate abstract query > notation, though. I've tried other various things and they're all > uglier. That's not to say someone smarter can't come up with > something simpler and more flexible. They just need to implement it > for us. ;-) > > -- > Ryan Pavlik > > "You mean easily pawned valuable crystal orb thingie." - 8BT