4 ms·
Actually, some work on this has been done for CHICKEN Scheme in extensions "ssql" and "ssql-postgresql"[0]. I'm not too familiar with these particular eggs, bu
by jrapdx3 12y ago
Actually, some work on this has been done for CHICKEN Scheme in extensions "ssql" and "ssql-postgresql"[0]. I'm not too familiar with these particular eggs, but the flavor might be conveyed by this example:
(ssql->sql #f '(select (columns (col actors name)
(count (col roles id)))
(from roles actors)
(where (= (col roles actor_id) (col actors id)))
(group (col actors name))))
translates to "SELECT actors.name, COUNT(roles.id) FROM roles, actors WHERE (roles.actor_id = actors.id) GROUP BY actors.name"
In the above sexpr, the SQL query is expressed as a Scheme/Lisp hierarchical list, which I think is a quite elegant notation. I'm sure other Scheme implementations provide variations on this theme of SQL generation. Using some macro magic, there would certainly be a lot of ways to organize it and probably it's not even all that hard to do.
[0] documentation at: http://wiki.call-cc.org/eggref/4/ssql http://wiki.call-cc.org/eggref/4/ssql
- mtanski 12y agoIt's def a step in the right direction. At least in terms of letting you mechanically transform queries. The downside (IMO) is that it's still reflecting SQL the language ... not the relational model.