4 ms·
I don't get few things. 1. Queries are executed by passing your query and db-config to oj/exec. So, does it mean that with any new query there will be new conn
by krick 12y ago
I don't get few things.
1. Queries are executed by passing your query and db-config to oj/exec. So, does it mean that with any new query there will be new connection to db? How do you manage transaction, when doing inserts/updates? I suppose there must be some magic I don't understand, because if that stuff actually is unsupported that would make all thing pretty much unusable, wouldn't it? Well, if you are not using MySQL/MyISAM anyway.
2. I suppose that library does some internal sanitizing, because it is what such libraries usually are for after all. There isn't much sense in using keywords instead of strings if it is the same plain SQL you would write manually (well, you wouldn't make a typo in the word WHERE, but that's all). But I don't see any mentions of types whatsoever. So if I pass some variable foo to that query, how does it know how to validate and sanitize it? If it is allowed to be NULL? If it should be passed to query as INT or string or maybe DATETIME? As it is minimalistic I would assume it doesn't use schema (and how would it if it's not an ORM, but just some query composer?), so how does it work then?
There are few other things I frowned on, but these are the major points.
- taylorlapeyre 12y agoI'll try to address your concerns, but keep in mind: this is a very new project. 1. When you "exec" a query, all I'm really doing is compiling the query map into an SQL statement and passing it into java.jdbc[1] with the database configuration that is given. This database config can be stored as a regular Clojure map in a config namespace in your project or however you wish. To answer your question, yes, at the moment java.jdbc is called for each query that is executed and I can only assume that that means that a new connection is made. Obviously there is room for improvement here, which will be addressed in the future. 2. I've provided a thorough specification for what makes a Clojure map a "query map" in the SPEC file[2]. Before any query map is compiled into SQL, it gets validated by a function that ensures that it meets the specification. If not, it throws an error. Hopefully this answers some of your concerns! Like I said, this is a new project that I made for fun and for personal use. I plan on working on it for a long time, and I'm sure that many things will be improved! I hope that others find it useful (or at least interesting) as well. [1]: https://github.com/clojure/java.jdbc/ https://github.com/clojure/java.jdbc/ [2]: https://github.com/taylorlapeyre/oj/blob/master/doc/SPEC https://github.com/taylorlapeyre/oj/blob/master/doc/SPEC
- mschaef 12y agoRegarding point 1, java.jdbc can accept a variety of types of connection maps. The simplest scenario is you pass in a map that contains the connection information, and you get a new connection and transaction for each call. However, you can also pass in live connections/transactions that can be reused. The with-db-transaction form is one way to accomplish this. It's really pretty flexible. (And btw, your library looks really quite good! I'm glad people are trying to address the issue of generating SQL within Clojure.)