RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

Record Filter: An ActiveRecord query API for replacing SQL with awesome.

Record Filter is a pure-Ruby API for ActiveRecord that uses an expressive DSL to replace nasty hard-coded SQL with beautiful Ruby. It works seamlessly with your existing named scopes, but once you see it you might just want to rewrite them all. Check out the project home or the rdocs for more info.

Comments

Hm. What does this offer over the already-mature Sequel? See also the Sequel cheatsheet for examples.

And of course, as the author of M4DBI ORM, I still don’t get what the big aversion to SQL is. :)

Also looks a little like Squirrel, by the excellent Thoughtbot.

I don’t think there’s any reason to have an aversion to SQL per-se, but I do think that hardcoding SQL into your Ruby code leaves a lot to be desired. Certainly, a DSL that lets you express what you mean in a way that stays as close to the language that you think/write in seems a big improvement.

As for squirrel, it does have some of the same concepts, but note that record_filter also supports named filters (akin to named_scopes) that can be combined to form more powerful filters, which squirrel doesn’t seem to do. For one-off filters, I don’t see a dramatic difference after a quick glance, but I happen to like the syntax of record_filter a bit better (so, I’m biased).

Also, note that record_filter doesn’t itself intend to be an ORM, like Seqeuel, but is instead an extension of ActiveRecord.

@Aubrey: Looks neat, but I don’t see the benefit of hardcoding DSL code into your app rather than hardcoding SQL. They’re both DSLs, even if one is a lot uglier than the other. :)

For complex queries being able to abstract SQL into DSL methods is a very powerful feature, it allows you to do clever things. The alternative with raw SQL involves concatenating strings together to get your final query, which can be a ball ache. I welcome this addition to ActiveRecord

All my hoes stay in line now that I can chain them with my queries

Thanks Record Filter!

ActiveRecord (if your weapon of choice) lacks a lot of functionality, even basic stuff like OR instead of AND, which requires writing SQL.

Nothing wrong with SQL but if your using a DSL like ActiveRecord or Sequal its for a reason and this gem fills that gap.

Simple syntax, powerful queries.

Good job!

<a href=”http://www.biber-hapi1.net title=” rel=”nofollow” biber hapı”>biber hapı</a>

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in