diff --git a/pyon/datastore/couchdb/couchdb_config.py b/pyon/datastore/couchdb/couchdb_config.py index 92be764..49b7dd6 100644 --- a/pyon/datastore/couchdb/couchdb_config.py +++ b/pyon/datastore/couchdb/couchdb_config.py @@ -2,7 +2,6 @@ __author__ = 'Thomas R. Lennan, Michael Meisinger' __license__ = 'Apache 2.0' - COUCHDB_CONFIGS = { 'object_store':{ 'views': ['object','association'] @@ -13,6 +12,9 @@ COUCHDB_CONFIGS = { 'directory_store':{ 'views': ['directory'] }, + 'dm_datastore':{ + 'views': ['posts'] + }, 'all':{ 'views': ['object', 'resource', 'association', 'directory'] } @@ -148,10 +150,25 @@ function(doc) { }""", }, }, + 'posts':{ + 'index':{ + 'map':""" +function(doc) { + if(doc.type=="post") { + emit([doc._id,0],doc) + } else if (doc.type == "comment") { + emit([doc.post, 1], doc) + } +}""" + } + } } def get_couchdb_views(config): - store_config = COUCHDB_CONFIGS[config] + if config in COUCHDB_CONFIGS: + store_config = COUCHDB_CONFIGS[config] + else: + store_config = COUCHDB_CONFIGS['all'] views = store_config['views'] res_views = {} for view in views: diff --git a/pyon/datastore/couchdb/couchdb_datastore.py b/pyon/datastore/couchdb/couchdb_datastore.py index 648c46c..44d6ff0 100644 --- a/pyon/datastore/couchdb/couchdb_datastore.py +++ b/pyon/datastore/couchdb/couchdb_datastore.py @@ -574,7 +574,9 @@ class CouchDB_DataStore(DataStore): def _define_views(self, datastore_name=""): if not datastore_name: datastore_name = self.datastore_name - for design, viewdef in self.couchdb_views.iteritems(): + + views = get_couchdb_views(datastore_name) + for design, viewdef in views.iteritems(): self._define_view(design, viewdef, datastore_name=datastore_name) def _define_view(self, design, viewdef, datastore_name=""): @@ -591,8 +593,8 @@ class CouchDB_DataStore(DataStore): if not datastore_name: datastore_name = self.datastore_name db = self.server[datastore_name] - - for design, viewdef in self.couchdb_views.iteritems(): + views = get_couchdb_views(datastore_name) + for design, viewdef in views.iteritems(): for viewname in viewdef: try: rows = db.view("_design/%s/_view/%s" % (design, viewname))