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.
Chipping the web – kicks — Chip’s Quips