public static void UpdateDesignDocuments(CouchDatabase db) { var view = new CouchDesignDocument("explosionview"); foreach (var pair in views) { var processed = pair.Value.Replace("$MODEL_NAME", typeof(Note).Name); view.Views.Add(pair.Key, new CouchView(processed)); } db.CreateDocument(view, new Result<CouchDesignDocument>()).WhenDone((designDocument) => { Console.Out.WriteLine("Successfully written design doc!"); }, (designDocumentError) => { Console.Out.WriteLine("Hah, couldn't write design doc: " + designDocumentError.Message); }); }
private Yield LoadContactsHelper(Result<ViewResult<string,string, Contact>> aResult) { Result<bool> exists = new Result<bool>(); yield return theDatabase.DocumentExists("_design/contactview", exists); if(exists.HasException){ aResult.Throw(exists.Exception); yield break; } if (!exists.Value) { CouchDesignDocument view = new CouchDesignDocument("contactview"); view.Views.Add("all", new CouchView( @"function(doc){ if(doc.type && doc.type == 'contact'){ emit(doc.lastName, doc.firstName) } }")); Result<CouchDesignDocument> creationResult = new Result<CouchDesignDocument>(); yield return theDatabase.CreateDocument(view, creationResult); if(creationResult.HasException) { aResult.Throw(creationResult.Exception); yield break; } } var viewRes = new Result<ViewResult<string, string, Contact>>(); yield return theDatabase.GetView("contactview", "all",viewRes); if(viewRes.HasException) { aResult.Throw(viewRes.Exception); yield break; } aResult.Return(viewRes.Value); }