Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've actually seriously considered keeping all my SQL queries in their own files, and reading them into local variables on load. It would allow them to be tracked and edited individually... but I now use an ORM.


I do keep the SQL queries in their own files. The only difference is that they get loaded into the db (as stored procs) at first and then called by name. Works well.


This is called the Phrasebook pattern and was probably being pushed as best practise until ORM's took hold.

* http://ootips.org/yonat/patterns/phrasebook.html

* http://www.perl.com/pub/2002/10/22/phrasebook.html

* https://metacpan.org/module/Data::Phrasebook::SQL


The point being that ORMs have limitations. Advocating that something is 'one-size-fits-all' is foolish (not claiming that that's what you're doing).


> .. but I now use an ORM.

"ORM is an anti-pattern": http://seldo.com/weblog/2011/08/11/orm_is_an_antipattern


Agreed ORM's are usually very sub-optimal. They make sense only because application developers aren't db people. And this is the problem.

I suspect for certain parts of some apps, ORM's might work OK. But in general for applications of any complexity they will break down hard and fast, and lead to bad db design, bad performance, or both.


ORM is just less work. If you write in OOP you are already creating objects anyways. Then writing get, save, and update procedures is just a lot of extra work.


The problem is then you build databases around your ORM but if you are doing a single app database, why use an RDBMS at all?

In other words, I see an ORM as an antipattern because the subset of cases where it works really well at bridging the gap you probably don't really want an RDBMS in there anyway.

And if you do make it work (encapsulating your db behind updatable views) without running into this, it's a heck of a lot more work than hand-coding SQL.....




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: