I would agree that the latter is less 'nasty' in that it is a query written in a DSL designed to make querying tabular data more understandable. It would be a major failing of SQL if that were not the case.
However, what the former does that the latter does not is provide a mechanism to build up and modify queries. It can be very helpful to pass around and affect partial queries when you are looking to eliminate repetitive code for building multiple, similar queries.
This is probably why many abstraction layers have query builders that look a lot like the syntax that you call nasty to generate the 'less nasty' raw SQL.
So, basically you're saying it's OK that the abstraction layer for RethinkDB creates nasty code because it's native JS? I don't agree. I think nasty code is never OK.
Why can't the RethinkDB abstraction layer just be better? Why isn't:
var dateFilter = new Date();
dateFilter = dateFilter.setDate(dateFilter.getDate() - 30);
rdb.table('users').get([ { column: signup_date, gt: dateFilter } ]).each(function (err, user) {
// Do stuff
});
Possible? That's just off the top of my head how I would do it in a way that's native JS and far better than what's presented in the article.
Using an anonymous function like in the first example is optional. `r.row` can be very convenient. In this case, you only need to use `r.row` because you're using the `gt` comparison. If you're just doing a direct match, you can use this syntax:
Maybe we can agree that we have different definitions of what 'better' is. I can understand the design decisions and trade-offs that would likely have been considered in designing the API as presented.
I'm also a bit wary of trying to introduce too much 'magic' just to make things convenient.
However, what the former does that the latter does not is provide a mechanism to build up and modify queries. It can be very helpful to pass around and affect partial queries when you are looking to eliminate repetitive code for building multiple, similar queries.
This is probably why many abstraction layers have query builders that look a lot like the syntax that you call nasty to generate the 'less nasty' raw SQL.