public virtual void TestPostKeysView() { Send("PUT", "/db", Status.Created, null); IDictionary <string, object> result; Database db = manager.GetDatabase("db"); View view = db.GetView("design/view"); view.SetMapAndReduce(new _Mapper_463(), null, "1"); IDictionary <string, object> key_doc1 = new Dictionary <string, object>(); key_doc1["parentId"] = "12345"; result = (IDictionary <string, object>)SendBody("PUT", "/db/key_doc1", key_doc1, Status .Created, null); view = db.GetView("design/view"); view.SetMapAndReduce(new _Mapper_475(), null, "1"); IList <object> keys = new AList <object>(); keys.AddItem("12345"); IDictionary <string, object> bodyObj = new Dictionary <string, object>(); bodyObj["keys"] = keys; URLConnection conn = SendRequest("POST", "/db/_design/design/_view/view", null, bodyObj ); result = (IDictionary <string, object>)ParseJSONResponse(conn); NUnit.Framework.Assert.AreEqual(1, result["total_rows"]); }
public static Query GetQuery(Database database, string listDocId) { View view = database.GetView(ViewName); if (view.Map == null) { view.Map += (IDictionary<string, object> document, EmitDelegate emitter)=> { if (Task.DocType.Equals(document.Get("type"))) { var keys = new AList<object>(); keys.AddItem(document.Get("list_id")); keys.AddItem(document.Get("created_at")); emitter(keys, document); } }; } Query query = view.CreateQuery(); query.Descending = true; IList<object> startKeys = new AList<object>(); startKeys.AddItem(listDocId); startKeys.AddItem(new Dictionary<string, object>()); IList<object> endKeys = new AList<object>(); endKeys.AddItem(listDocId); query.StartKey = startKeys; query.EndKey = endKeys; return query; }
static Conversation() { database = Manager.SharedInstance.GetDatabase ("conversations"); defaultView = database.GetView ("conversation-messages"); defaultView.SetMap ((document, emit) => { // }, "1"); }
public static Query GetQuery(Database database, string ignoreUserId) { View view = database.GetView(ViewName); if (view.GetMap() == null) { Mapper map = new _Mapper_30(ignoreUserId); view.SetMap(map, null); } Query query = view.CreateQuery(); return query; }
public static Query GetQueryById(Database database, string userId) { View view = database.GetView(ByIdViewName); if (view.GetMap() == null) { Mapper map = new _Mapper_52(); view.SetMap(map, null); } Query query = view.CreateQuery(); IList<object> keys = new AList<object>(); keys.AddItem(userId); query.SetKeys(keys); return query; }
public static View CreateView(Database db) { var view = db.GetView("aview"); view.SetMapReduce((IDictionary <string, object> document, EmitDelegate emitter) => { Assert.IsNotNull(document["_id"]); Assert.IsNotNull(document["_rev"]); if (document["key"] != null) { emitter(document["key"], null); } }, null, "1"); return(view); }
public static Query GetQuery(Database database) { View view = database.GetView(ViewName); if (view.Map == null) { view.Map += (IDictionary<string, object> document, EmitDelegate emitter) => { string type = (string)document.Get("type"); if (List.DocType.Equals(type)) { emitter(document.Get("title"), document); } }; } Query query = view.CreateQuery(); return query; }
public static Query GetQuery(Database database) { var view = database.GetView(ViewName); if (view.Map == null) { view.SetMap((document, emitter) => { object deleted; document.TryGetValue(DeletedKey, out deleted); if(deleted == null) emitter (document["text"], document["check"]); }, "2"); } var query = view.CreateQuery(); return query; }
public static Query GetQuery(Database database) { var view = database.GetView(ViewName); if (view.Map == null) { view.SetMap((document, emitter) => { object type; document.TryGetValue("type", out type); if (List.DocType.Equals ((string)type)) { emitter (document["text"], document); } }, "1"); } var query = view.CreateQuery(); return query; }
static ContactDatabase() { database = Manager.SharedInstance.GetDatabase ("contacts"); emailLookup = new Dictionary<string, string> (); lookupView = database.GetView ("addresses"); lookupView.SetMap ((document, emit) => { var val = document["contact.address.address"]; emit(document["_id"], val); }, "1"); Query lookupQuery = lookupView.CreateQuery (); BuildLookup(lookupQuery.Run ()); lookupViewLiveQuery = lookupQuery.ToLiveQuery(); lookupViewLiveQuery.Changed += (object sender, QueryChangeEventArgs e) => { BuildLookup(e.Rows); }; lookupViewLiveQuery.Start (); }
private void InitializeCouchbase() { _db = Manager.SharedInstance.GetDatabase("wpf-lite"); var view = _db.GetView("todos"); if (view.Map == null) { view.SetMap((props, emit) => { Console.WriteLine("Mapper mapping"); emit(DateTime.UtcNow.ToString(), props["text"]); }, "1"); } _query = view.CreateQuery().ToLiveQuery(); _query.Changed += QueryChanged; _query.Completed += QueryCompleted; _query.Start(); }
public TaskManager () { _db = Manager.SharedInstance.GetDatabase("kitchen-sync"); View view = _db.GetView("viewItemsByDate"); view.SetMap((doc, emit) => { if(doc.ContainsKey("created_at") && doc["created_at"] is DateTime) { emit(doc["created_at"], null); } }, "1"); _query = view.CreateQuery().ToLiveQuery(); _query.Descending = true; _query.Changed += (sender, e) => { if(TasksUpdated != null) { var tasks = from row in e.Rows select Task.FromDictionary(row.Document.Properties); TasksUpdated(this, tasks.ToList()); } }; _query.Start(); }
private void InitializeCouchbase() { _db = Manager.SharedInstance.GetDatabase("wpf-lite"); _viewModel = new SimpleViewModel(new SimpleModel(Manager.SharedInstance, "wpf-lite")); if (_viewModel.SyncURL != null) { UpdateReplications(_viewModel.SyncURL); } _viewModel.PropertyChanged += (sender, args) => { Console.WriteLine("Replication URL changed to {0}", _viewModel.SyncURL); UpdateReplications(_viewModel.SyncURL); }; var view = _db.GetView("todos"); if (view.Map == null) { view.SetMap((props, emit) => { object date; if (!props.TryGetValue(CREATION_DATE_PROPERTY_NAME, out date)) { return; } object deleted; if (props.TryGetValue("_deleted", out deleted)) { return; } emit(date, props["text"]); }, "1"); } _query = view.CreateQuery().ToLiveQuery(); _query.Changed += QueryChanged; _query.Start(); }
public virtual void TestViews() { Send("PUT", "/db", Status.Created, null); IDictionary <string, object> result; IDictionary <string, object> doc1 = new Dictionary <string, object>(); doc1["message"] = "hello"; result = (IDictionary <string, object>)SendBody("PUT", "/db/doc1", doc1, Status.Created , null); string revID = (string)result["rev"]; IDictionary <string, object> doc3 = new Dictionary <string, object>(); doc3["message"] = "bonjour"; result = (IDictionary <string, object>)SendBody("PUT", "/db/doc3", doc3, Status.Created , null); string revID3 = (string)result["rev"]; IDictionary <string, object> doc2 = new Dictionary <string, object>(); doc2["message"] = "guten tag"; result = (IDictionary <string, object>)SendBody("PUT", "/db/doc2", doc2, Status.Created , null); string revID2 = (string)result["rev"]; Database db = manager.GetDatabase("db"); View view = db.GetView("design/view"); view.SetMapAndReduce(new _Mapper_372(), null, "1"); // Build up our expected result IDictionary <string, object> row1 = new Dictionary <string, object>(); row1["id"] = "doc1"; row1["key"] = "hello"; IDictionary <string, object> row2 = new Dictionary <string, object>(); row2["id"] = "doc2"; row2["key"] = "guten tag"; IDictionary <string, object> row3 = new Dictionary <string, object>(); row3["id"] = "doc3"; row3["key"] = "bonjour"; IList <IDictionary <string, object> > expectedRows = new AList <IDictionary <string, object > >(); expectedRows.AddItem(row3); expectedRows.AddItem(row2); expectedRows.AddItem(row1); IDictionary <string, object> expectedResult = new Dictionary <string, object>(); expectedResult["offset"] = 0; expectedResult["total_rows"] = 3; expectedResult["rows"] = expectedRows; // Query the view and check the result: Send("GET", "/db/_design/design/_view/view", Status.Ok, expectedResult); // Check the ETag: URLConnection conn = SendRequest("GET", "/db/_design/design/_view/view", null, null ); string etag = conn.GetHeaderField("Etag"); NUnit.Framework.Assert.AreEqual(string.Format("\"%d\"", view.GetLastSequenceIndexed ()), etag); // Try a conditional GET: IDictionary <string, string> headers = new Dictionary <string, string>(); headers["If-None-Match"] = etag; conn = SendRequest("GET", "/db/_design/design/_view/view", headers, null); NUnit.Framework.Assert.AreEqual(Status.NotModified, conn.GetResponseCode()); // Update the database: IDictionary <string, object> doc4 = new Dictionary <string, object>(); doc4["message"] = "aloha"; result = (IDictionary <string, object>)SendBody("PUT", "/db/doc4", doc4, Status.Created , null); // Try a conditional GET: conn = SendRequest("GET", "/db/_design/design/_view/view", headers, null); NUnit.Framework.Assert.AreEqual(Status.Ok, conn.GetResponseCode()); result = (IDictionary <string, object>)ParseJSONResponse(conn); NUnit.Framework.Assert.AreEqual(4, result["total_rows"]); }
public static View CreateView(Database db) { var view = db.GetView("aview"); view.SetMapReduce((IDictionary<string, object> document, EmitDelegate emitter)=> { Assert.IsNotNull(document["_id"]); Assert.IsNotNull(document["_rev"]); if (document["key"] != null) { emitter(document["key"], null); } }, null, "1"); return view; }
public static View CreateView(Database db) { View view = db.GetView("aview"); view.SetMapReduce(new _Mapper_172(), null, "1"); return view; }
void Start() { DontDestroyOnLoad(this); if (FindObjectsOfType(GetType()).Length > 1) { Destroy(gameObject); return; } manager = Manager.SharedInstance; db = manager.GetDatabase(Constants.DB_NAME); db.Changed += (sender, e) => { var changes = e.Changes.ToList(); foreach (DocumentChange change in changes) { print("Document " + change.DocumentId + " changed"); } }; // initialize views // account username-password View viewAccount = db.GetView(Constants.DB_TYPE_ACCOUNT); viewAccount.SetMap ((doc, emit) => { if(doc[Constants.DB_KEYWORD_TYPE].ToString () == Constants.DB_TYPE_ACCOUNT) emit(doc[Constants.DB_KEYWORD_USERNAME], doc[Constants.DB_KEYWORD_PASSWORD]); }, "1"); // initialize database, use Unity inspector to change value in GameManager if (GameManager.Instance.initializeDatabase) { InitializeDatabase(); } }