Re: resultset-seq improvement: mapping column names

2010-12-06 Thread Allen Johnson
+1

On Fri, Dec 3, 2010 at 10:25 PM, ka  wrote:
> I'm also stuck with the same issues: 1. no option to get string keys
> 2. I don't understand, why do libs go through the trouble of
> downcasing ?
>
> Having said that I totally agree with the point Ryan makes: >> A
> greater feature of clojure is its extensibility.  What I am after is a
> generalization of the function in question, for greater
> interoperability with Java's SQL libraries.
>
> --
> 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 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


Re: resultset-seq improvement: mapping column names

2010-12-03 Thread ka
I'm also stuck with the same issues: 1. no option to get string keys
2. I don't understand, why do libs go through the trouble of
downcasing ?

Having said that I totally agree with the point Ryan makes: >> A
greater feature of clojure is its extensibility.  What I am after is a
generalization of the function in question, for greater
interoperability with Java's SQL libraries.

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


Re: resultset-seq improvement: mapping column names

2010-12-01 Thread Ryan Twitchell
Sean,
I entirely agree that the use of keywords as map keys is a feature of
clojure (and a great one, at that), and that converting result set
column names to keywords is a feature of resultset-seq.  A greater
feature of clojure is its extensibility.  What I am after is a
generalization of the function in question, for greater
interoperability with Java's SQL libraries.  Matching data from
resultset-seq back to its ResultSet (or source tables) currently
involves a few too many nuances for my comfort.

And while most implementations of SQL are case insensitive, most of
these also preserve the case of column names.  I'm not a fan of
camelCase identifiers at all, but they're out there.  stringify is too
blunt for my needs.

Ryan

On Dec 1, 11:57 am, Sean Devlin  wrote:
> Using keywords in the resultset map is a feature.  It is very common
> to write something like this;
>
> (map :your-column results)
>
> This takes advantage of the fact that keywords implement IFn.  To the
> best of my knowledge SQL isn't case sensitive, downcasing the column
> names makes sense too, since it is more idiomatic.
>
> If you really want to stringify the columns, I suggest keeping the
> following code handy:
>
> (defn stringify [m]
>   (into {} (map (fn [k v] [(name k) v])))
>
> The simply call map
>
> (map stringify results)
>
> Sean
>
> On Dec 1, 10:01 am, Ryan Twitchell  wrote:
>
> > Hi all,
>
> > I'm not too happy with how resultset-seq down-cases column names and
> > turns them into keywords, as I would prefer to work with string keys
> > in some cases.  I came up with the following change to give the caller
> > a choice to remap column keys in any way.  This leaves resultset-seq's
> > behavior for a single argument exactly as it was before.
>
> > ;; Instead of:
> > user> (resultset-seq rs)
> > ({:empid 3} {:empid 4} ...)
>
> > ;; We can do this:
> > user> (resultset-seq rs identity) ;; or any remapping fn
> > ({"empId" 3} {"empId" 4} ...)
>
> > I'd love to see the change made to core.  If not, I hope this helps
> > others who have had the same problem:
>
> >https://gist.github.com/723583
>
> > And though I'm not thrilled with this, for coping with contrib.sql's
> > with-query-results macro (which uses resultset-seq) I have the
> > following:
>
> > (defmacro with-query-results2
> >   "Like clojure.contrib.sql/with-query-results, but returns structmaps
> > with
> > String keys identical to those in the ResultSet.  This is done by
> > dynamically
> > rebinding clojure.core/resultset-seq to a new function, so take care
> > if using
> > that function within body."
> >   [results sql-params & body]
> >   `(binding [resultset-seq #(resultset-seq2 % identity)]
> >      (with-query-results ~results ~sql-params ~...@body)))

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


Re: resultset-seq improvement: mapping column names

2010-12-01 Thread Shantanu Kumar
+1

On Dec 1, 8:01 pm, Ryan Twitchell  wrote:
> Hi all,
>
> I'm not too happy with how resultset-seq down-cases column names and
> turns them into keywords, as I would prefer to work with string keys
> in some cases.  I came up with the following change to give the caller
> a choice to remap column keys in any way.  This leaves resultset-seq's
> behavior for a single argument exactly as it was before.
>
> ;; Instead of:
> user> (resultset-seq rs)
> ({:empid 3} {:empid 4} ...)
>
> ;; We can do this:
> user> (resultset-seq rs identity) ;; or any remapping fn
> ({"empId" 3} {"empId" 4} ...)
>
> I'd love to see the change made to core.  If not, I hope this helps
> others who have had the same problem:
>
> https://gist.github.com/723583
>
> And though I'm not thrilled with this, for coping with contrib.sql's
> with-query-results macro (which uses resultset-seq) I have the
> following:
>
> (defmacro with-query-results2
>   "Like clojure.contrib.sql/with-query-results, but returns structmaps
> with
> String keys identical to those in the ResultSet.  This is done by
> dynamically
> rebinding clojure.core/resultset-seq to a new function, so take care
> if using
> that function within body."
>   [results sql-params & body]
>   `(binding [resultset-seq #(resultset-seq2 % identity)]
>      (with-query-results ~results ~sql-params ~...@body)))

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


Re: resultset-seq improvement: mapping column names

2010-12-01 Thread Sean Devlin
Using keywords in the resultset map is a feature.  It is very common
to write something like this;

(map :your-column results)

This takes advantage of the fact that keywords implement IFn.  To the
best of my knowledge SQL isn't case sensitive, downcasing the column
names makes sense too, since it is more idiomatic.

If you really want to stringify the columns, I suggest keeping the
following code handy:

(defn stringify [m]
  (into {} (map (fn [k v] [(name k) v])))

The simply call map

(map stringify results)

Sean

On Dec 1, 10:01 am, Ryan Twitchell  wrote:
> Hi all,
>
> I'm not too happy with how resultset-seq down-cases column names and
> turns them into keywords, as I would prefer to work with string keys
> in some cases.  I came up with the following change to give the caller
> a choice to remap column keys in any way.  This leaves resultset-seq's
> behavior for a single argument exactly as it was before.
>
> ;; Instead of:
> user> (resultset-seq rs)
> ({:empid 3} {:empid 4} ...)
>
> ;; We can do this:
> user> (resultset-seq rs identity) ;; or any remapping fn
> ({"empId" 3} {"empId" 4} ...)
>
> I'd love to see the change made to core.  If not, I hope this helps
> others who have had the same problem:
>
> https://gist.github.com/723583
>
> And though I'm not thrilled with this, for coping with contrib.sql's
> with-query-results macro (which uses resultset-seq) I have the
> following:
>
> (defmacro with-query-results2
>   "Like clojure.contrib.sql/with-query-results, but returns structmaps
> with
> String keys identical to those in the ResultSet.  This is done by
> dynamically
> rebinding clojure.core/resultset-seq to a new function, so take care
> if using
> that function within body."
>   [results sql-params & body]
>   `(binding [resultset-seq #(resultset-seq2 % identity)]
>      (with-query-results ~results ~sql-params ~...@body)))

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


resultset-seq improvement: mapping column names

2010-12-01 Thread Ryan Twitchell
Hi all,

I'm not too happy with how resultset-seq down-cases column names and
turns them into keywords, as I would prefer to work with string keys
in some cases.  I came up with the following change to give the caller
a choice to remap column keys in any way.  This leaves resultset-seq's
behavior for a single argument exactly as it was before.

;; Instead of:
user> (resultset-seq rs)
({:empid 3} {:empid 4} ...)

;; We can do this:
user> (resultset-seq rs identity) ;; or any remapping fn
({"empId" 3} {"empId" 4} ...)

I'd love to see the change made to core.  If not, I hope this helps
others who have had the same problem:

https://gist.github.com/723583

And though I'm not thrilled with this, for coping with contrib.sql's
with-query-results macro (which uses resultset-seq) I have the
following:

(defmacro with-query-results2
  "Like clojure.contrib.sql/with-query-results, but returns structmaps
with
String keys identical to those in the ResultSet.  This is done by
dynamically
rebinding clojure.core/resultset-seq to a new function, so take care
if using
that function within body."
  [results sql-params & body]
  `(binding [resultset-seq #(resultset-seq2 % identity)]
 (with-query-results ~results ~sql-params ~...@body)))

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