couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Update of "DumpOracleDbToCouchDbPython" by DougShawhan
Date Fri, 13 Nov 2009 21:43:41 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The "DumpOracleDbToCouchDbPython" page has been changed by DougShawhan.
http://wiki.apache.org/couchdb/DumpOracleDbToCouchDbPython?action=diff&rev1=4&rev2=5

--------------------------------------------------

          gm.updateCouch( table_name )
  }}}
  
+ = Unique Values in SQL Table Converted to a Single Document =
+ 
+ Differs from above in that 
+ 
+ This probably isn't what you want either!
+ 
+ {{{#!python
+ # HEY! THIS VERSION CAN MAKE A MOTHER-HUGE DOCUMENT! KNOW WHAT YOU ARE DOING!!!
+ # Convert a list of (sql tables, unique identifiers) into a single couchDB document
+ # Switch out with updateCouch() above
+ 
+     def updateCouch( self, table_and_key ):
+         # populate or update couchdb documents using sql table and unique
+         # identifier
+         # HEY! THIS CAN MAKE A MOTHER-HUGE DOCUMENT! KNOW WHAT YOU ARE DOING!!!
+         self.table_name, self.mykey = table_and_key
+ 
+         cursor = cx_Oracle.Cursor( self.connection )
+         documents = []
+         header = self.description()
+ 
+         query = """
+             select %s
+             from %s 
+             order by %s"""""%( ", ".join( header ),
+                                     self.table_name,
+                                     self.mykey ) 
+ 
+         cursor.execute( query )
+         results = dict(
+                 [ ( str( row[0] ), dict( 
+                     [ (k, v) for k, v in zip( header, row ) ] 
+                     ) ) for row in cursor.fetchall() 
+                 ] )
+ 
+         # clean up any datetime fields
+         for row in results:
+             for field in results[ row ]:
+                 if isinstance( results[ row ][ field ], datetime.datetime ):
+                     results[ row ][ field ] = "%s"%results[ row ][ field ]
+         self.db[ self.table_name ] = results
+ 
+         cursor.close()
+ }}}
+ 

Mime
View raw message