I have been wondering whether there is any code out there that enables representing SQL in the form of some object tree that can be assembled, modified and then finally rendered to valid SQL?
Off the top of my head it could look something like that...
var stmnt = new Statement();
stmnt
.AddMaster("Customer")
.Show("Firstname, "Lastname")
.AddJoin("Address", "ID", "CustomerID")
.Show("Street", "City");
stmnt.WhereStatement()
.AddParameter("Address.City", Op.Equal);
string sql = stmnt.Generate();
// select a.FirstName, a.LastName, b.Street, b.City
// from Customer a
// join Address b on b.CustomerID = a.ID
// where b.City = :p1
This is just an example and the thing out there may work totally different, but yes, I'd love to hear what is out tere in that respect.
UPDATE:
I am aware of the numerous possibilities of using ORM technologies to get my results from the DB, but I was after a model for the SQL itself. I know that the level of abstraction is pretty low, but it could possibly allow a situation where multiple collaborators can work on an SQL statement (multiple joins, multiple wheres) which can then be "rendered" at the end of the build-Phase.