4 ms·
The unfortunate thing is that there really isn't a tradeoff if you build your elegant and simple DSL on top of a set of API primitives that give you access to l
by donw 14y ago
The unfortunate thing is that there really isn't a tradeoff if you build your elegant and simple DSL on top of a set of API primitives that give you access to low-level behavior.
Look at Hibernate. As of the last time I used it (admittedly, several years ago), it was almost impossible to run raw queries against the underlaying database and get back simple result sets as arrays of tuples. You had either the abstraction, or nothing.
With ActiveRecord, you can at least get at the underlaying database connection via select_all and select_values, and turn Relations into SQL queries via '#to_sql'. It's not perfect by any stretch, and for some reason I don't understand Arel decided that being able to OR two queries together wasn't important, but you can leave the abstraction when you need to.
(Mongoid, the MongoDB ORM, is actually really well-designed in this regard; the Mongoid::Criteria works like Arel should, as does Sequel...)
- jbverschoor 14y agoSorry, but Hibernate has been far superior to ActiveRecord from day one. ActiveRelation is very similar to the criteria api, but it still uses string parsign. HQL is awesome. That said, I haven't done Java for 3 years and am a 100% rubyist (and some lua) The developments of rails are good. But they are simply all the stuff that maturing platforms will need. Rails is becoming JEE, but in a more developer friendly way. This is a good thing.
- steveklabnik 14y ago> it still uses string parsign This is false, at least after tenderlove did all his work to re-write arel.
- donw 14y agoKeep in mind that I'm not an ActiveRecord fan; the internal architecture drives me nuts, but I do like that I can use SQL when I want to, without ActiveRecord getting in the way. Here's the first Google hit I came across when looking to use PostgreSQL fulltext searches under Hibernate: https://forum.hibernate.org/viewtopic.php?p=2447426 https://forum.hibernate.org/viewtopic.php?p=2447426 That's 50+ lines of code, plus some XML configuration, spread over four files, to perform a highly database-specific task that could have been better handled in raw SQL in a single line of code. Also if I remember correctly, Hibernate, like DataMapper, requires that you specify your field types in the code, which makes migrations (updates to the DDL) a royal pain in the ass, and migrations are an important task in the operational lifecycle of an application. I'm a big believer in having sole sources of truth, and so I treat the database as the only source for information about the structure of the database -- I don't want to have to specify that information in two places, where it can get out of sync. Now, it's been years since I touched Hibernate, and it's probably gotten better. But from what I can tell, the above issues are design decisions; part of a conscious effort to hide the internals of the database from the developer, no matter the cost. This is why people claim that ORM is an antipattern. Because, while an ORM solves 90% of your problems, for that remaining 10%, nothing beats being able to talk directly to the backend.
- jbverschoor 14y agoThat 50 lines is adding functionality in HQL.. How much work is it to add a fts() method to active relation + active record? To execute custom sql, simply: sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE FROM CATS").list(); one line of code.