1. Mar 9th, 2007

    SQL DSL

    I’ve done SQL in just about any language I worked with, from the painful C to the shameful Access/VB, and I’d rather just stick to using SQL. There are a lot of nice APIs that abstract SQL, but you need to learn a new API every time you switch framework or language, so it’s not exactly a transferrable skill. Not that SQL was ever a hard language to learn, it’s managing your database access that’s the real problem, and abstractions don’t make it any easier.

    So a DSL for SQL is not my cup of tea. Regardless, I really urge you to check out what Jay Fields is doing. Impressive.

    Select[:column1].from[:table1, :table2].where do
      table1.column1 = table2.table1_id
      table1.column2 >= quantity if quantity > 0
    end

    For one, it looks extremely easy to use and solves most of the annoying quoting problems (and resulting SQL injection bugs). If you want control over your SQL without the stringifying aches, this is it.

    For another, it’s one of the best DSLs I’ve seen in Rubyland. There’s a lot of great ideas you can pick from it for your own DSL. A couple of things I didn’t know were possible, and love to do in future projects. I wish for a library that will make writing DSLs like that easier. Drop me a note if you’re working on that.

    And if that’s not enough, there’s also bragging rights. Just think of all the people stuck in .Net world, waiting for Microsoft to grace them with updates to LINQ ever so seldom. Then think of all the people stuck in the Java world that don’t even have that. And smile.

    Because in Ruby, if you need it, you just make it happen.

    1. Mar 9th, 2007

      Chipping the web – kicks — Chip’s Quips

      [...] Ruby DSL for SQL, “Because in Ruby, if you need it, you just make it [...]

    2. Mar 12th, 2007

      Kevin Clark

      Are you missing a do after the where?

    3. Mar 12th, 2007

      Assaf

      I guess I was that impressed with SQL DSL, I copied the example without noticing the bug.

    4. Nov 17th, 2007

      Michael Hunger

      I did something similar in Java, but with compile time safety and type completion in regard to Tables and Column Names. Its called Jequel and can be found at http://jequel.de. Something like the closures in Ruby is nice for handling all the late evaluation transformed to expression tree stuff, we’re working on something like this with load time bytecode injection for the expression trees in Quaere.

    Your comment, here ⇓