From Queries to ORMs

Let me start this by saying that I know I’m trying to do the thing in the reverse way, but what the heck! ;)

So, a few months ago I decided to write the queries for my Web Gallery application. Why? ‘Cause I had no idea how to do it and I think it’s fun to play directly with SQL. Honestly, I couldn’t find a way, but asking some friends, we did come with a good solution. All of the queries are quite simple, except for this one (the one that retrieves all URLs [soon to be replaced by pics] which have a set of tags):


select urls.url, urls.description, urls.id from urls where (select count(1) from relation where relation.url = urls.id and relation.tag in (%s)) >= %d

[The “%s” is the list of tags and the “%d” is the number of tags]

So, this query works perfectly fine. But we are in the times of Web 2.0, where no one writes queries anymore and queries are like black magic and stuff. So yes, I’m thinking about using an ORM, but I can’t see how one ORM would be capable to reaching the same solution (or a better one) for that.

I just got to a point where I don’t believe an ORM would be capable of reaching a sane solution for what I want and I think it’s stupid to import and ORM into my project just to insert a direct query.