News for hackers. Stuff that matters.
Re:Why I Hate Frameworks by dools on Wednesday July 20, 2011 @09:28PM (#2788168)
Yeah most ORMs have a "custom SQL" option - what I mean is this (example in some non-existant language):

  function something(db_obj)
    print db_obj.getSql() #shows SQL built so far
    db_obj.having('SOMETHING = SOMETHING ELSE')
    db_obj.fromClause(this.bizarreCaseStatement()
    db_obj.order(this.weirdoOrderClauseThatReferencesCaseStatement());
    return db_obj
When I start working with db_obj, it might come from some other part of the application for which the "basic ORM" was just fine.

Now I want to add some weirdo custom stuff in but I can't - I have to go back to the part of the application that produced db_obj in the first place and refactor that to use custom SQL.

It's one or the other.

Re:Why I Hate Frameworks by mnutt on Wednesday July 20, 2011 @09:42PM (#2788190)
Check out ARel. (it's in ActiveRecord 3, part of Rails) It uses relational algebra and is pretty good about letting you mix and match:

    enabled = User.where(:disabled => false)
    enabled.group("date(created_at)").having("created_at > ?", 1.month.ago).order(weird_order_clause).limit(5)
Re:Why I Hate Frameworks by dools on Wednesday July 20, 2011 @10:14PM (#2788254)
Right, yeah that's pretty nice!
Re:Why I Hate Frameworks by eropple on Thursday July 21, 2011 @01:14AM (#2788597)
The CodeIgniter ActiveRecord library follows the same pattern. Unfortunately, it's pretty kludgey and requires you to use CodeIgniter.
Re:Why I Hate Frameworks by Xurinos on Thursday July 21, 2011 @10:49AM (#2789702)
Do you have an example that shows how to use ARel to do relational algebra?
Re:Why I Hate Frameworks by mnutt on Friday July 22, 2011 @12:25PM (#2794159)
I believe it just uses it under the hood, but I'm not familiar enough with relational algebra (or ARel) to know for sure. Here's a blog post from the author:

http://magicscalingsprinkles.wordpress.com/2010/01/28/why-i-...

Re:Why I Hate Frameworks by ehutch79 on Thursday July 21, 2011 @01:17PM (#2790325)
Re:Why I Hate Frameworks by smunz on Wednesday July 20, 2011 @09:46PM (#2788198)
I think activerecord in rails 3 comestibles Odette close - except the modification of from.
Re:Why I Hate Frameworks by mcao on Thursday July 21, 2011 @01:49AM (#2788639)
That sounds like something I wrote.

https://github.com/mikecao/sparrow

It's a simple class that builds and executes SQL, but you can customize query at any time.

Re:Why I Hate Frameworks by troels on Thursday July 21, 2011 @04:36AM (#2788871)
There's php-activerecord[1] or if you want something a bit different, do take a look at notorm[2]. I'd also take this opportunity to mention my own creation, pdoext[3].

[1] https://github.com/kla/php-activerecord

[2] https://github.com/vrana/notorm

[3] https://github.com/troelskn/pdoext

Re:Why I Hate Frameworks by jcromartie on Wednesday July 20, 2011 @10:45PM (#2788333)
ClojureQL (also based on relational algebra like the other comment) lets you compose bits and pieces of queries a lot like that.
Re:Why I Hate Frameworks by EGreg on Thursday July 21, 2011 @10:58AM (#2789754)
Yeah phponpie.com has that :)

$u = new User(); $u->id = 69; $u->retrieve(true)->having( )->orderBy( )->resume();

something like that :)