On Wed, Sep 18, 2013 at 09:27:22AM -0700, Daniel Neal wrote:
> One other difference I did notice with clojureql is that in clojureql the 
> database/connection
> is part of the query definition `(table db :users)`, where as in 
> clojure-sql the database/connection
> is a separate thing. This seemed more orthogonal to me, but in practice I 
> found it a bit tricky when working with multiple databases as I kept having 
> to change global state - is there a better way of handling multiple 
> databases using clojure-sql (perhaps I need to write my own query 
> executor...?)

Yeah, writing your own executor is a good option. Personally I would
write one which returns a function of the database, like this:

(set-query-executor! (fn [type query]
                       (fn [db]
                         (jdbc/with-connection db
                           (case type
                             :select (jdbc/with-query-results results query
                                       (dotted-to-nested-maps results))
                             :insert (jdbc/do-prepared-return-keys (first 
query) (next query))
                             :update (jdbc/do-prepared-return-keys (first 
query) (next query))
                             :delete (first (jdbc/do-prepared (first query) 
(next query)))
                             (assert false (str "Unknown query type: " 
type)))))))

Then you can use (@query db) to run queries, and the slightly-clunkier
((insert! query record ...) db) to modify the database. (I haven't
tried running this code, so it may require some modification to actually
work.)

In my use case I am always working with a single database, so I thought
this approach would be a bit overkill as the default.

> 1. Are there any known issues/not-implemented-yet bits I might run into 
> when using clojure-sql?

Almost certainly, but I don't know all of the issues. So far it's been
working for what I've needed it for (which is a fairly small subset of
SQL, admittedly).

I'm not happy with the way the grouping stuff works at the moment, but
at the moment I've not really had much time to fix it. It should work,
but you lose the ability to freely compose things once you do a group
(because a select being applied later can change the group result).

> 2. What plans do you have for the library going forward?

A few things, when I get a chance, mostly to do with generalising the
relational algebra approach beyond just SQL. I'd like to make it so
queries can be executed against other possible data stores (eg. an
in-memory structure, files on disk) efficiently.

As part of this would also be re-thinking how queries are executed.
Obviously, as you've seen above, the executor stuff isn't quite as nice
as it could be. I don't like having the global state stuff, but I wanted
executing queries to be both easy and configurable.

I'd also like to start generating SQL for other databases. I've been
putting this off because I don't really have any need for it at the
moment and it's a fair bit of work to do properly.

Carlo

-- 
-- 
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.

Reply via email to