4 ms·
So this is Linq for Ruby. Using this in place of ActiveRecord's querying API will be great. One nice thing about Linq though is that most (all?) of the methods
by dmnd 17y ago
So this is Linq for Ruby. Using this in place of ActiveRecord's querying API will be great.
One nice thing about Linq though is that most (all?) of the methods on IEnumerable have the same semantics as those on IQueryable. Ruby has a pretty nice Enumerable, but the method names in Arel don't match up. Map becomes project, select is where, etc.
It's convenient to be able to use the same syntax to query an in memory object collection that you use to query a database (or any other kind of abstract collection).
- davidmathers 17y agoMap and project aren't the same thing. Map can't be part of the algebra because it breaks the closure property. Project is a single, specific function. I agree with your sentiment though. It looks like Nick took names from SQL where available ("where") and from relational algebra otherwise ("project"). I would rather the names came from ruby first.
- dmnd 17y agoI don't know much (anything) about relational algebra or breaking closure properties, so I'm glad my sentiment was clear despite that error. Is project different from map because it can only output a subset of the attributes that go in, whereas an arbitrary thing can come out of map?
- davidmathers 17y agoExactly. Project is just an operator that takes a table and gives you a table with a different number of attributes. All the relational operations take and return table values (aka relation values), which is what makes the algebra closed under operations. SQL select actually combines project and map (with select...as) by letting you define maps for the individual attributes of the table. That's fine since you can't break the table structure. You just can't map on tables or table rows.