Re:OrmHate
by crazygringo on Tuesday June 26, 2012 @01:52PM
(#4163208)
No, ORM's provide object-relational mapping, and all sorts of functions for building up queries as part of that. They don't provide an API for common queries at all. I don't even know what "all the common queries" would be... beyond get-a-value-for-pkey, every app is totally different in the kinds of queries it needs.
What I described isn't a homebrew data layer or building an ORM, it's just a few helpful shortcut functions for queries.
Re:OrmHate
by ubernostrum on Tuesday June 26, 2012 @02:10PM
(#4163331)
I hate to break it to you, but there are about as many definitions of "ORM" as there are of things like "functional programming".
What you have described would be considered, by many ORM critics, to be ORM.
Re:OrmHate
by crazygringo on Tuesday June 26, 2012 @03:10PM
(#4163644)
Aw, MAAAAN... Oh well, OK...
> every app is totally different in the kinds of queries it needs
There is more to SQL than queries. Every app need insert, updat, and delete, and a basic select 1 and select many matching a predicate. Those can all be automated; that's what ORM's do, they automate the repetitive simple stuff.
More complex queries that strain the ORM's abilities can be done in SQL in a view, and then mapped in by querying the view with the ORM. Or you can just drop into raw SQL when necessary. Every app is not different, they are largely all very similar.
Making a homebrew data layer isn't avoiding an ORM, it's building one.
> If you find yourself writing the same query structure 20 times, then create a function for it.
What do you think ORM's do? That is what they do, they provide a standard API for all the common queries.