Hi,
I propose to add new query formats:
diff --git a/doc/postmodern.html b/doc/postmodern.html index 3691ae8..9ac466f 100644 --- a/doc/postmodern.html +++ b/doc/postmodern.html @@ -202,6 +202,10 @@ row.</td></tr> <tr><td><code>:list</code>, <code>:row</code></td><td>Return a single row as a list.</td></tr> + <tr><td><code>:plists</code></td><td>Return a list of plists which map column + names to values,with the names represented as + keywords.</td></tr> + <tr><td><code>:plist</code></td><td>Return a single row as an plist.</td></tr> <tr><td><code>:alists</code></td><td>Return a list of alists which map column names to values,with the names represented as keywords.</td></tr> diff --git a/postmodern/query.lisp b/postmodern/query.lisp index 3e5bfa5..921d03d 100644 --- a/postmodern/query.lisp +++ b/postmodern/query.lisp @@ -9,6 +9,15 @@ :for symbol :in symbols :collect (cons symbol (next-field field))))))
+;; Like symbol-alist-row-reader, but return plist +(def-row-reader symbol-plist-row-reader (fields) + (let ((symbols (map 'list (lambda (desc) (from-sql-name (field-name desc))) fields))) + (loop :while (next-row) + :collect (loop :for field :across fields + :for symbol :in symbols + :collect symbol + :collect (next-field field))))) + ;; A row-reader for reading only a single column, and returning a list ;; of single values. (def-row-reader column-row-reader (fields) @@ -22,6 +31,8 @@ (:list list-row-reader t) (:rows list-row-reader nil) (:row list-row-reader t) + (:plists symbol-plist-row-reader nil) + (:plist symbol-plist-row-reader t) (:alists symbol-alist-row-reader nil) (:alist symbol-alist-row-reader t) (:str-alists alist-row-reader nil)
Moskvitin Andrey
Hi Andrey,
Thanks for submitting a patch. But -- why plists? Do you have some library for which you need results like this?
Best, Marijn
On Fri, Mar 26, 2010 at 10:56 PM, Andrey Moskvitin archimag@gmail.com wrote:
Hi, I propose to add new query formats: diff --git a/doc/postmodern.html b/doc/postmodern.html index 3691ae8..9ac466f 100644 --- a/doc/postmodern.html +++ b/doc/postmodern.html @@ -202,6 +202,10 @@ row.</td></tr> <tr><td><code>:list</code>, <code>:row</code></td><td>Return a single row as a list.</td></tr>
- <tr><td><code>:plists</code></td><td>Return a list of plists which
map column
- names to values,with the names represented as
- keywords.</td></tr>
- <tr><td><code>:plist</code></td><td>Return a single row as an
plist.</td></tr> <tr><td><code>:alists</code></td><td>Return a list of alists which map column names to values,with the names represented as keywords.</td></tr> diff --git a/postmodern/query.lisp b/postmodern/query.lisp index 3e5bfa5..921d03d 100644 --- a/postmodern/query.lisp +++ b/postmodern/query.lisp @@ -9,6 +9,15 @@ :for symbol :in symbols :collect (cons symbol (next-field field))))))
+;; Like symbol-alist-row-reader, but return plist +(def-row-reader symbol-plist-row-reader (fields)
- (let ((symbols (map 'list (lambda (desc) (from-sql-name (field-name
desc))) fields)))
- (loop :while (next-row)
- :collect (loop :for field :across fields
- :for symbol :in symbols
- :collect symbol
- :collect (next-field field)))))
;; A row-reader for reading only a single column, and returning a list ;; of single values. (def-row-reader column-row-reader (fields) @@ -22,6 +31,8 @@ (:list list-row-reader t) (:rows list-row-reader nil) (:row list-row-reader t)
- (:plists symbol-plist-row-reader nil)
- (:plist symbol-plist-row-reader t)
(:alists symbol-alist-row-reader nil) (:alist symbol-alist-row-reader t) (:str-alists alist-row-reader nil)
Moskvitin Andrey _______________________________________________ postmodern-devel mailing list postmodern-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel
But -- why plists? Do you have some library for which you need results like this?
Yes, my template library cl-closure-template ( http://code.google.com/p/cl-closure-template/) required plists as input data. In my experience code based on the plist is usually easier to write and understand.
Andrey
Fair enough. Applied and pushed.
Oh, probably after this patch was another that made it invalid. I upgraded to version 1.16 and noticed the problem.
Correction:
diff --git a/postmodern/query.lisp b/postmodern/query.lisp index 3832fca..bca6e71 100644 --- a/postmodern/query.lisp +++ b/postmodern/query.lisp @@ -34,8 +34,8 @@ (:alist symbol-alist-row-reader single-row) (:str-alists alist-row-reader all-rows) (:str-alist alist-row-reader single-row) - (:plists symbol-plist-row-reader nil) - (:plist symbol-plist-row-reader t) + (:plists symbol-plist-row-reader all-rows) + (:plist symbol-plist-row-reader single-row) (:column column-row-reader all-rows) (:single column-row-reader single-row) (:single! column-row-reader single-row!))
Andrey
Argh. This looked so simple that I didn't even test it. You must have been working against an *ancient* version. Fix applied.
On 26 March 2010 23:51, Marijn Haverbeke marijnh@gmail.com wrote:
Hi Andrey,
Thanks for submitting a patch. But -- why plists? Do you have some library for which you need results like this?
FWIW, i've had a plist row reader in RELATIONAL-OBJECTS-FOR-LISP since pretty much day 1. I'm not sure why i didn't send a patch... probably because i didn't think of it as more generally useful as i have a lot of different, more specific row readers.
Anyway, thought i'd chime in.
Cheers,
drewc
Best, Marijn
On Fri, Mar 26, 2010 at 10:56 PM, Andrey Moskvitin archimag@gmail.com wrote:
Hi, I propose to add new query formats: diff --git a/doc/postmodern.html b/doc/postmodern.html index 3691ae8..9ac466f 100644 --- a/doc/postmodern.html +++ b/doc/postmodern.html @@ -202,6 +202,10 @@ row.</td></tr> <tr><td><code>:list</code>, <code>:row</code></td><td>Return a single row as a list.</td></tr>
- <tr><td><code>:plists</code></td><td>Return a list of plists which
map column
- names to values,with the names represented as
- keywords.</td></tr>
- <tr><td><code>:plist</code></td><td>Return a single row as an
plist.</td></tr> <tr><td><code>:alists</code></td><td>Return a list of alists which map column names to values,with the names represented as keywords.</td></tr> diff --git a/postmodern/query.lisp b/postmodern/query.lisp index 3e5bfa5..921d03d 100644 --- a/postmodern/query.lisp +++ b/postmodern/query.lisp @@ -9,6 +9,15 @@ :for symbol :in symbols :collect (cons symbol (next-field field))))))
+;; Like symbol-alist-row-reader, but return plist +(def-row-reader symbol-plist-row-reader (fields)
- (let ((symbols (map 'list (lambda (desc) (from-sql-name (field-name
desc))) fields)))
- (loop :while (next-row)
- :collect (loop :for field :across fields
- :for symbol :in symbols
- :collect symbol
- :collect (next-field field)))))
;; A row-reader for reading only a single column, and returning a list ;; of single values. (def-row-reader column-row-reader (fields) @@ -22,6 +31,8 @@ (:list list-row-reader t) (:rows list-row-reader nil) (:row list-row-reader t)
- (:plists symbol-plist-row-reader nil)
- (:plist symbol-plist-row-reader t)
(:alists symbol-alist-row-reader nil) (:alist symbol-alist-row-reader t) (:str-alists alist-row-reader nil)
Moskvitin Andrey _______________________________________________ postmodern-devel mailing list postmodern-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel
postmodern-devel mailing list postmodern-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel
postmodern-devel@common-lisp.net