On Jan 7, 6:49 am, Ken Wesson <kwess...@gmail.com> wrote:
> On Thu, Jan 6, 2011 at 7:33 PM, Sean Corfield <seancorfi...@gmail.com> wrote:
> > On Thu, Jan 6, 2011 at 2:33 AM, LauJensen <lau.jen...@bestinclass.dk> wrote:
> >> Yes the two statements are equivalent. ClojureQL compiles everything
> >> to prepared
> >> statements, with every argument automatically paramterized.
>
> > Cool, that's what I'd hoped. But just to clarify...
>
> > If I have code that repeatedly calls this:
>
> > @(-> (table :user)
> >     (select (where (= :id user-id)))
> >     (project [:dateofbirth :gender :zipcode]))
>
> > it is going to construct that AST and compile it to SQL every time it
> > hits it, yes?
>
> I'd hope it has some kind of caching or memoization behind the scenes,
> but if not, that'd be a great thing to add for version 1.1. I think a
> typical database client app uses a finite variety of prepared
> statements (each with potentially changing parameter values), so
> straight memoization ought to do fine and clojure already natively
> supports that, so ...

The tricky part is - a PreparedStatement object is created and is
valid only in the context of a Connection object (because statement
compilation is database specific, and often needs an extra roundtrip
to the database). So, unless we are reusing the Connection object
prepared statements need to be created repeatedly and nullifies the
benefit of caching/memoization across several database connections.
Good use-cases for PreparedStatement include batch queries.

An optimization thought: Instead of re-using a Connection object for
all queries (and re-create if necessary), use a DataSource and have
separate Connection objects for each major use-case so that
PreparedStatement objects can be memoized and remain valid for long.

Regards,
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

Reply via email to