InfoQ

News

Abstracting Data Query in Ruby with Ambition Ambition

Posted by Sebastien Auvray on Sep 26, 2007 02:00 AM

Community
Ruby
Topics
Data Access
Tags
LINQ ,
Database
One of today's challenges is to reduce the complexity of accessing and integrating information from various sources. While .NET already has such LINQ, Ruby had no such solution. There are existing DSL projects for querying with Ruby but not as Ruby.

Chris Wanstrath brings his own solution: Ambition.  Ambition takes advantage of ParseTree to walk the parse tree and translate plain Ruby queries into SQL (when the target is a Relational Database), so at the end you'll be able to write your queries the Ruby way:

User.first
# which will translate into "SELECT * FROM users LIMIT 1"
User.select { |u| u.karma > 20 }.sort_by(&:karma).first(5)
# which will translate into "SELECT * FROM users WHERE (users.`karma` > 20)
# ORDER BY users.karma LIMIT 5"


While originally Chris was gunning for Rack, he changed his target since he discovered LINQ.
We’ve moved our sights from Rack to LINQ. That is, we don’t want to only support other ORMs—we want Ambition to be a query language for SQL, LDAP, XPath, the works. The 1.0 release will be backend-agnostic. Maybe then we’ll change the name to Hubris? Time will tell.
You can find latest sources at git://errtheblog.com/git/ambition
Another Groovy plug :) by Tom Nichols Posted Sep 26, 2007 7:16 AM
Re: Another Groovy plug :) by Werner Schuster Posted Sep 27, 2007 3:53 AM
  1. Back to top

    Another Groovy plug :)

    Sep 26, 2007 7:16 AM by Tom Nichols

    GORM does this very well too, although the approach is a bit different. I think I like this syntax better. At some point GORM will support JPA, which (if I understand correctly) means it should be able to query XML and such as well.

  2. Back to top

    Re: Another Groovy plug :)

    Sep 27, 2007 3:53 AM by Werner Schuster

    There might be overlap in the querying features, but not in the approach. Following your link, GORM seems to use Builders or string queries, or something that seems to use the Groovy version of method_missing. However, Ambition works by actually looking at the AST of the queries, and as such is similar to Macros in languages like LISP or Scheme. The link to LINQ (pun intended) is that LINQ uses the same approach. Of course, the results of the various solutions are the same, but the approaches are different. Question is how well Ruby syntax lends itself to Macros: the Ambition queries still need to be legal Ruby code, otherwise it couldn't be parsed. This is different in LISP, since there isn't much syntax to speak of in the first place. Of course, taking a peek at LINQ can help here.

Educational Content

Bindings, Platforms, and Innovation

This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.

Orchestrating Long Running Activities with JBoss / JBPM

This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.

Neo4j - The Benefits of Graph Databases

This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.

Realistic about Risk: Software development with Real Options

This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.

Communication Flexibility Using Bindings

This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.

Writing DSLs in Groovy

After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.

Scaling Agile with C/ALM (Collaborative Application Lifecycle Management)

IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.

Concurrent Programming with Microsoft F#

Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.