by dools · 15y ago · 0 comments
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.
enabled = User.where(:disabled => false)
enabled.group("date(created_at)").having("created_at > ?", 1.month.ago).order(weird_order_clause).limit(5)http://magicscalingsprinkles.wordpress.com/2010/01/28/why-i-...
see: https://docs.djangoproject.com/en/1.3/topics/db/queries/#com... https://docs.djangoproject.com/en/dev/topics/db/queries/#fil...
https://github.com/mikecao/sparrow
It's a simple class that builds and executes SQL, but you can customize query at any time.
[1] https://github.com/kla/php-activerecord
$u = new User(); $u->id = 69; $u->retrieve(true)->having( )->orderBy( )->resume();
something like that :)