What is Arel in Rails 3.0?
This is an object model for the algebra of relational query operators.
I understand that this is a replacement for ActiveRecord
No, it is not. This is a replacement for manual SQL queries in rows. This is the usual query level that underlies ActiveRecord, but it can also be used, for example, to support DataMapper.
If it's a replacement for anything, it's a replacement for Ambition. Or you can think of it as a Ruby version of the standard LINQ or Python SQLAlchemy queries. (In fact, the author explicitly refers to LINQ and SQLAlchemy as inspiration.)
Or you can see it as a replacement for named_scope s. In fact, AREL pretty much represents the idea that "every request is named_scope ". And, whaddayaknow: both were written by the same guy.
and that it uses objects instead of queries.
No, it uses objects as queries.
why is it better?
Ruby is an object oriented language, not a string language. For this reason, it makes sense to represent queries as objects instead of strings. Creating the right object model for queries instead of using strings for everything gives you pretty much the same advantages as creating the right object model for an accounting system, and not using strings for everything gives you.
Another big advantage is that AREL implements a real algebra of query operators. In other words, AREL is aware of the mathematical rules for constructing and compiling queries. If you concatenate two rows, each of which contains a valid SQL query, the result will probably not be a valid SQL query. Or, even worse, this is a valid SQL query, but one that doesn't make sense, or something completely different from what you think. This will never happen with AREL. (This is what I refer to below, meaning "closed in composition.")
Will objects / queries be "easier" to create?
Yes. For example, as I mentioned above, it is much easier to create more complex queries from simpler parts.
will result in more efficient SQL queries?
Yes. The fact that AREL has the proper object model for queries means that it can perform optimizations on those queries long before it ever generates an actual SQL query.
Is it compatible with all major databases? - I guess it will be.
Yes. In fact, I always talked about SQL above, but in fact, relational query algebra can generate queries for just about anything. Again, see LINQ or Ambition for examples: both can query SQL, LDAP, ActiveResource, CouchDB, Amazon, Google, & hellip; all with the same syntax.
Perhaps the best discussion of what AREL is and why Nick Kallen wrote is a well-titled article Why Arel? Nick Cullen . Note. The article contains a small mild mathematical and informational jargon, but itโs exactly the same: AREL has some solid foundations in mathematics and computer science, these foundations are what gives it its powerful properties.