changeset 51:17dcf148beb3

more JSON store
author casties
date Thu, 09 Sep 2010 10:01:16 +0200
parents 29c822d15bc1
children 435d6664ed90
files RestDbJsonStore.py
diffstat 1 files changed, 62 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/RestDbJsonStore.py	Wed Sep 08 12:03:15 2010 +0200
+++ b/RestDbJsonStore.py	Thu Sep 09 10:01:16 2010 +0200
@@ -178,11 +178,72 @@
         sql = 'select distinct json_tag from "%s"."%s"'%(schema,table)
         res = self.executeSQL(sql)
         if len(res['rows']) > 0:
-            tags = [r[0] for r in rows]
+            tags = [r[0] for r in res['rows']]
+            return tags
+        
+        return []
+    
+    def showListOfTypes(self,resultFormat,schema,table,tag):
+        """returns the list of existing types"""
+        types = self.getListOfTypes(schema, table,tag)
+        if resultFormat == 'JSON':
+            self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
+            json.dump(types, self.REQUEST.RESPONSE)        
+        else:
+            json.dump(types, self.REQUEST.RESPONSE)        
+        
+    def getListOfTypes(self,schema,table,tag):
+        """returns the list of existing tags"""
+        logging.debug("getlistoftypes schema=%s table=%s tag=%s"%(schema,table,tag))
+        sql = 'select distinct json_type from "%s"."%s" where json_tag = %%s'%(schema,table)
+        res = self.executeSQL(sql,(tag,))
+        if len(res['rows']) > 0:
+            tags = [r[0] for r in res['rows']]
             return tags
         
         return []
     
+    def showListOfItems(self,resultFormat,schema,table,tag,type):
+        """returns the list of existing items"""
+        items = self.getListOfItems(schema, table, tag, type)
+        if resultFormat == 'JSON':
+            self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
+            json.dump(items, self.REQUEST.RESPONSE)        
+        else:
+            json.dump(items, self.REQUEST.RESPONSE)        
+        
+    def getListOfItems(self,schema,table,tag,type):
+        """returns the list of existing tags"""
+        logging.debug("getlistofitems schema=%s table=%s tag=%s type=%s"%(schema,table,tag,type))
+        sql = 'select distinct json_item from "%s"."%s" where json_tag = %%s and json_type = %%s'%(schema,table)
+        res = self.executeSQL(sql,(tag,type))
+        if len(res['rows']) > 0:
+            items = [r[0] for r in res['rows']]
+            return items
+        
+        return []
+    
+    def showItem(self,resultFormat,schema,table,tag,type,item):
+        """returns the item"""
+        item = self.getItem(schema, table, tag, type, item)
+        if resultFormat == 'JSON':
+            self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
+            json.dump(item, self.REQUEST.RESPONSE)        
+        else:
+            json.dump(item, self.REQUEST.RESPONSE)        
+        
+    def getItem(self,schema,table,tag,type,item):
+        """returns the list of existing tags"""
+        logging.debug("getitem schema=%s table=%s tag=%s type=%s item=%s"%(schema,table,tag,type,item))
+        sql = 'select json_value from "%s"."%s" where json_tag = %%s and json_type = %%s and json_item = %%s'%(schema,table)
+        res = self.executeSQL(sql,(tag,type,item))
+        if len(res['rows']) > 0:
+            # just one item
+            item = res['rows'][0][0]
+            return item
+        
+        return {}
+    
 manage_addRestDbJsonStoreForm=PageTemplateFile('zpt/addRestDbJsonStore',globals())
 
 def manage_addRestDbJsonStore(self, id, title='', label='', description='',