public void Should_Return_View_Results_As_JObject()
        {
            CouchDatabase db = client.GetDatabase(baseDatabase);

            db.CreateDocument(new JDocument());
            db.CreateDocument(new JDocument());
            db.CreateDocument(new JDocument());

            JObject result = db.GetView("testviewitem", "testview", new Result <JObject>()).Wait();

            Assert.IsNotNull(result);
            Assert.IsNotNull(result["rows"]);
        }
        public void Should_Return_View_Results()
        {
            CouchDatabase db = client.GetDatabase(baseDatabase);

            db.CreateDocument(new JDocument());
            db.CreateDocument(new JDocument());
            db.CreateDocument(new JDocument());

            ViewResult <string, JObject> result = db.GetView("testviewitem", "testview", new Result <ViewResult <string, JObject> >()).Wait();

            Assert.IsNotNull(result);
            Assert.IsTrue(result.TotalRows > 0);
        }
Esempio n. 3
0
        public List <Item> GetItems()
        {
            List <Item> items       = new List <Item>();
            CouchClient couchClient = new CouchClient("192.168.1.100", 5984, null, null);

            CouchDatabase db         = couchClient.GetDatabase(itemsDB);
            JObject       viewResult = db.GetView("itemsDesignDoc", "getAllItems");

            foreach (JObject doc in viewResult.GetValue("rows"))
            {
                JDocument itemstDoc = db.GetDocument <JDocument>((doc.GetValue("id").ToString()));
                items.Add(Item.FromJson(itemstDoc.ToString()));
            }
            couchClient = null;

            return(items);
        }
Esempio n. 4
0
        public List <Account> GetAccounts()
        {
            List <Account> accounts    = new List <Account>();
            CouchClient    couchClient = new CouchClient("192.168.1.100", 5984, null, null);

            CouchDatabase db         = couchClient.GetDatabase(accountsDB);
            JObject       viewResult = db.GetView("accountsDesignDoc", "getAllAccounts");

            foreach (JObject doc in viewResult.GetValue("rows"))
            {
                JDocument accountDoc = db.GetDocument <JDocument>((doc.GetValue("id").ToString()));
                accounts.Add(Account.FromJson(accountDoc.ToString()));
            }

            couchClient = null;

            return(accounts);
        }
Esempio n. 5
0
        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);
        }
        public void Should_Return_View_Results_With_Documents()
        {
            CouchDatabase db = client.GetDatabase(baseDatabase);

            db.CreateDocument(new JDocument());
            db.CreateDocument(new JDocument());
            db.CreateDocument(new JDocument());

            ViewResult <string, JObject, JDocument> result = db.GetView <string, JObject, JDocument>("testviewitem", "testview");

            Assert.IsNotNull(result);
            foreach (ViewResultRow <string, JObject, JDocument> row in result.Rows)
            {
                Assert.IsNotNull(row.Doc);
                Assert.IsNotNull(row.Key);
                Assert.IsNotNull(row.Id);
                Assert.IsNotNull(row.Value);
            }
        }