Hi Alex, On Wednesday, 8 January 2014 13:28:29 UTC+5:30, Alexander Hudek wrote: > > Hey everyone, > > We've been exploring ways to make working with database code more > efficient and less error prone. > For complex queries, we prefer working directly with SQL. However, like > for many others, a lot of our > queries are very simple and repetitive. For example, retrieving or > updating single rows, or a set of rows > based on a foreign key. >
I totally agree with this. I have noticed this is the most common scenario when working with SQL databases. > > As an experiment, we wrote a prototype that uses the information_schema > standard to automatically > extract the schema from a database and represent it as clojure code at > compile time. With this, we > were able to synthesize some simple SQL queries. The interesting part of > this is that the code generator > automatically picks up primary key constraints and also performs > validation on table and column names. > All of this is done at compile time. Errors are caught early and the > compiled code uses clojure.java.jdbc > prepared statements. You can find the code and demo here: > > https://github.com/diligenceengine/edl > > I'm personally not a big fan of huge ORM systems, so I don't know where to > go with this, if anywhere. > Though it seems useful for building small macros for common patterns we > have. > > Would love to hear if anyone has thoughts on the technique. > The approach to read the database to generate code is pretty interesting. There is a more portable way to extract the schema information, using DatabaseMetadata that you can extract from a Connection. http://docs.oracle.com/javase/7/docs/api/java/sql/DatabaseMetaData.html http://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html#getMetaData() Shantanu -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.