Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>res will be bound to a Clojure sequence based on the ResultSet where each item is a map of a result record with output column names as keywords in keys. You can't get to the underlying actual ResultSet object. </p> <p>Typically you don't call next at all. To be idiomatic Clojure, you would utilize the vast library of functions that operate on sequences (map, filter, reduce, etc) to produce your output. Here you might say something like:</p> <pre><code>(with-query-results res ["SELECT guid from users WHERE email=?" email] (map :guid res)) </code></pre> <p>which would apply :guid as a function over the res seqeuence and retrieve the column value of guid in each record, returning you a new sequence of all the guids. You could then wrap that map in a filter or whatever else you needed.</p> <p>In this case, <code>seq</code> should be what you want but I think the abstraction is leaking a bit. When I tried it I got <em>java.sql.SQLRecoverableException: Closed Resultset: next</em> which implies to me the ResultSet is being closed too early in the abstraction. However, I found <code>empty?</code> worked ok for this use case. </p> <pre><code>(defn user-exists? [email] (with-connection db (with-query-results res ["SELECT guid from users WHERE email=?" email] (.next res) (not (empty? res))))) </code></pre> <p>This seems like a bug in clojure.core/resultset-seq to me and I reported it here as <a href="http://dev.clojure.org/jira/browse/CLJ-676" rel="nofollow">CLJ-676</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload