changeset 266:342e96de6de6

json not quite there
author catherine@Elli.myhome.westell.com
date Mon, 16 Mar 2009 23:30:41 -0400
parents 041c656dc8e5
children 95195ec92c6c
files sqlpython/output_templates.py sqlpython/sqlpython.py
diffstat 2 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/output_templates.py	Mon Mar 16 22:20:53 2009 -0400
+++ b/sqlpython/output_templates.py	Mon Mar 16 23:30:41 2009 -0400
@@ -14,6 +14,13 @@
   </${tblname}_resultset>
 </xml>"""),
 
+'\\j': genshi.template.NewTextTemplate("""
+{"${tblname}_resultset: [{% for row in rows %}
+    "${tblname}": {{% for (colname, itm) in zip(colnames, row) %}
+        "${colname.lower()}": "${itm}",{% end %} },
+    {% end %}]
+}"""),  
+      
 '\\h': genshi.template.MarkupTemplate("""
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns:py="http://genshi.edgewall.org/" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
--- a/sqlpython/sqlpython.py	Mon Mar 16 22:20:53 2009 -0400
+++ b/sqlpython/sqlpython.py	Mon Mar 16 23:30:41 2009 -0400
@@ -216,6 +216,7 @@
 \\G   aligned list
 \\h   HTML table
 \\i   INSERT statements
+\\j   JSON
 \\s   CSV (with headings)
 \\S   CSV (no headings)
 \\t   transposed