tuamigo

Untitled

Oct 4th, 2013
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1.    
  2.  
  3.     import couchdb
  4.      
  5.     class connector(object):
  6.             def __init__(self, dbname):
  7.                     couch = couchdb.Server()
  8.                     try:
  9.                             self.__db = couch[dbname]
  10.                     except:
  11.                             raise Exception #Implementar excepcion
  12.      
  13.            
  14.             #Devuelve la lista de todos los eventos
  15.             def get_events(self):
  16.                     map_fun = '''function(doc) {
  17.                                    if (doc.type == 'Event') {
  18.                                            emit(doc.date, {Creator: doc.creator, Date: doc.date, Description: doc.description, Tags: doc.tags, Type: doc.type});
  19.                                            }
  20.                                    }'''
  21.      
  22.                     results = self.__db.query(map_fun)
  23.                     ls = list(results)
  24.                     return ls
  25.      
  26.             #Deuvle la lista de usuarios
  27.             def get_users(self):
  28.                     map_fun = '''function(doc) {
  29.                                    if (doc.type == 'User') {
  30.                                            emit(doc.type, {Description: doc.description, Subjects: doc.subjects, Subtype: doc.subtype, Type: doc.type});
  31.                                            }
  32.                                    }'''
  33.                     results = self.__db.query(map_fun)
  34.                     ls = list(results)
  35.                     return ls
Advertisement
Add Comment
Please, Sign In to add comment