static Conversation() { database = Manager.SharedInstance.GetDatabase ("conversations"); defaultView = database.GetView ("conversation-messages"); defaultView.SetMap ((document, emit) => { // }, "1"); }
//*** JavaScript View ***// private Couchbase.Lite.View CompileView(Database db, string viewName, JObject viewProps) { JToken language; if (!viewProps.TryGetValue("language", out language)) { language = "javascript"; } JToken mapSource; if (!viewProps.TryGetValue("map", out mapSource)) { return(null); } IViewCompiler viewCompiler = Couchbase.Lite.View.Compiler; IViewCompiler test = new JSViewCompilerCopy(); Couchbase.Lite.View.Compiler = test; MapDelegate mapBlock = Couchbase.Lite.View.Compiler.CompileMap(mapSource.Value <string>(), language.Value <string>()); if (mapBlock == null) { return(null); } string mapID = db.Name + ":" + viewName + ":" + mapSource.Value <string>().GetHashCode(); JToken reduceSource = null; ReduceDelegate reduceBlock = null; if (viewProps.TryGetValue("reduce", out reduceSource)) { // Couchbase.Lite.View.compiler est null et Couchbase.Lite.Listener.JSViewCompiler est inaccessible (même avec la reflection) reduceBlock = Couchbase.Lite.View.Compiler.CompileReduce(reduceSource.Value <string>(), language.Value <string>()); if (reduceBlock == null) { return(null); } mapID += ":" + reduceSource.Value <string>().GetHashCode(); } Couchbase.Lite.View view = db.GetView(viewName); view.SetMapReduce(mapBlock, reduceBlock, mapID); JToken collation = null; if (viewProps.TryGetValue("collation", out collation)) { if ("raw".Equals((String)collation)) { // ??? } } return(view); }
internal Query(Database database, View view) { // null for _all_docs query Database = database; View = view; Limit = Int32.MaxValue; MapOnly = (view != null && view.Reduce == null); IndexUpdateMode = IndexUpdateMode.Before; AllDocsMode = AllDocsMode.AllDocs; }
Couchbase.Lite.View GetView(string name) { Couchbase.Lite.View cbView = null; try { cbView = db.GetView(name); } catch (CouchbaseLiteException e) { Console.WriteLine(e.StackTrace); Log.Error(TAG, "Cannot get view", e.StackTrace); } return(cbView); }
public ObservableCollection <Dictionary <string, string> > recuperarDocs(string esport, string user) { Couchbase.Lite.View a = db.GetView("running2"); a.SetMap((document, emit) => { if ((string)document ["esportista"] == user && (string)document ["tipus"] == esport) { emit((string)document ["tipus"], document); } }, "1"); LogQueryResultsAsync(a); return(LogQueryResultsAsync(a)); }
private Couchbase.Lite.View CheckAndCreateJavaScriptView(Database database, string ddocName, string viewName) { string tdViewName = ddocName + "/" + viewName; Couchbase.Lite.View view = database.GetExistingView(tdViewName); Document rev = database.GetExistingDocument(C8oFullSync.FULL_SYNC_DDOC_PREFIX + "/" + ddocName); if (rev == null) { return(null); } string revID = rev.CurrentRevisionId; if (view != null) { string mapVersion = view.MapVersion; if (mapVersion == null || !viewDDocRev.ContainsKey(mapVersion) || !revID.Equals(viewDDocRev[mapVersion])) { view = null; } } if (view == null || view.Map == null) { // No TouchDB view is defined, or it hasn't had a map block assigned // Searches in the design document if there is a CouchDB view definition we can compile JObject views = rev.GetProperty(FULL_SYNC_VIEWS) as JObject; JToken viewProps; if (!views.TryGetValue(viewName, out viewProps)) { return(null); } view = CompileView(database, tdViewName, viewProps as JObject); if (view != null) { viewDDocRev[view.MapVersion] = revID; } } return(view); }
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 (); }
async void LogQueryResultsAsync(Couchbase.Lite.View cbView) { var orderedQuery = cbView.CreateQuery(); orderedQuery.Descending = true; orderedQuery.Limit = 20; try { var results = await orderedQuery.RunAsync(); results.ToList().ForEach(result => { var doc = result.Document; Log.Info(TAG, String.Format("Found document with id: {0}, Date = {1}", result.DocumentId, doc.GetProperty <string>("date"))); }); } catch (CouchbaseLiteException e) { Log.Error(TAG, "Error querying view", e); } catch (Exception e) { Log.Error(TAG, e.Message, e); } }
/// <summary> /// Gets the <see cref="Couchbase.Lite.View" /> with the given name, or null if it does not exist. /// </summary> /// <returns>The <see cref="Couchbase.Lite.View" /> with the given name, or null if it does not exist.</returns> /// <param name="name">The name of the View to get.</param> public View GetExistingView(String name) { View view = null; if (_views != null) { _views.TryGetValue(name, out view); } if (view != null) { return view; } view = new View(this, name); return view.Id == 0 ? null : RegisterView(view); }
private void OnViewChanged(View sender, EventArgs e) { _lastSequence = 0; Update(); }
void setupScannedView() { viewScanned = db.GetView ("scanned-by-employee"); var mapBlock = new MapDelegate ((doc, emit) => { object name; doc.TryGetValue ("employee", out name); object quantity; doc.TryGetValue ("quantity", out quantity); string q = quantity.ToString (); int quant; var ok = Int32.TryParse(q, out quant); if (ok && name != null) emit (name, quant); }); viewScanned.SetMapReduce (mapBlock, Couchbase.Lite.Views.BuiltinReduceFunctions.Sum, "1.1"); }
public View GetExistingView(string name) { View view = null; if (views != null) { view = views.Get(name); } if (view != null) { return view; } view = new View(this, name); if (view.GetViewId() == 0) { return null; } return RegisterView(view); }
public _Runnable_1847(View view) { this.view = view; }
void setupSoldView() { viewSold = db.GetView ("sold-by-employee"); var mapBlock = new MapDelegate ((doc, emit) => { object type; doc.TryGetValue ("type", out type); if (type != null) { string t = type.ToString (); if (t == "sale") { object name; doc.TryGetValue ("employee", out name); object quantity; doc.TryGetValue ("quantity", out quantity); string q = quantity.ToString (); int quant; var ok = Int32.TryParse(q, out quant); object price; doc.TryGetValue ("price", out price); string ps = price.ToString (); Single pnum; var ok2 = Single.TryParse(ps, out pnum); if (ok && ok2 && name != null) emit (name, quant * pnum); } } }); viewSold.SetMapReduce (mapBlock, Couchbase.Lite.Views.BuiltinReduceFunctions.Sum, "1.3"); }
internal static View MakeView(Database database, string name, bool create) { var storage = database.Storage.GetViewStorage(name, create); if (storage == null) { return null; } var view = new View(); view.Storage = storage; view.Database = database; storage.Delegate = view; view.Name = name; // means 'unknown' view.Collation = ViewCollation.Unicode; return view; }
public _AbstractTouchMapEmitBlock_428(View _enclosing) { this._enclosing = _enclosing; }
public void SetCollation(View.TDViewCollation collation) { this.collation = collation; }
private /*async*/ ObservableCollection <Dictionary <string, string> > LogQueryResultsAsync(Couchbase.Lite.View cbView) { var orderedQuery = cbView.CreateQuery(); orderedQuery.Descending = true; var llista = new ObservableCollection <Dictionary <string, string> >(); try { //var results = await orderedQuery.RunAsync (); var results = orderedQuery.Run(); Console.WriteLine("Found rows: {0}", results.Count); results.ToList().ForEach(result => { var doc = result.Document; Dictionary <string, string> aux = new Dictionary <string, string> { { "id", result.DocumentId }, { "nomCursa", doc.GetProperty <string>("nomCursa") }, { "dorsal", doc.GetProperty <string>("dorsal") }, { "posicio", doc.GetProperty <string>("posicio") }, { "distancia", doc.GetProperty <string>("distancia") }, { "posicioCategoria", doc.GetProperty <string>("posicioCategoria") }, { "categoria", doc.GetProperty <string>("categoria") }, { "club", doc.GetProperty <string>("club") }, { "iniciCursa", doc.GetProperty <string>("iniciCursa") }, { "tempsReal", doc.GetProperty <string>("tempsReal") }, { "tempsOficial", doc.GetProperty <string>("tempsOficial") }, { "iniciReal", doc.GetProperty <string>("iniciReal") }, { "horaMeta", doc.GetProperty <string>("horaMeta") }, { "ritme", doc.GetProperty <string>("ritme") }, { "km5", doc.GetProperty <string>("km5") }, { "horaKm5", doc.GetProperty <string>("horaKm5") }, { "km10", doc.GetProperty <string>("km10") }, { "horaKm10", doc.GetProperty <string>("horaKm10") }, { "tipus", doc.GetProperty <string>("tipus") }, { "esportista", doc.GetProperty <string>("esportista") } }; Console.WriteLine("Found document with id: {0}", result.DocumentId); var c = db.DocumentCount; Console.WriteLine("num DESPUES DE QUERY: " + c); llista.Add(aux); }); cbView.DeleteIndex(); Console.WriteLine("Num en la query: " + llista.Count); } catch (CouchbaseLiteException e) { Console.WriteLine("Error querying view", e.Message); } return(llista); }
// null view for _all_docs query internal Query(Database database, View view) { Debug.Assert(database != null); Database = database; View = view; Limit = Int32.MaxValue; MapOnly = (view != null && view.Reduce == null); InclusiveEnd = true; InclusiveStart = true; IndexUpdateMode = IndexUpdateMode.Before; AllDocsMode = AllDocsMode.AllDocs; }
public View RegisterView(View view) { if (view == null) { return null; } if (views == null) { views = new Dictionary<string, View>(); } views.Put(view.GetName(), view); return view; }
internal View RegisterView(View view) { if (view == null) { return null; } if (_views == null) { _views = new Dictionary<string, View>(); } _views.Put(view.Name, view); return view; }
internal Query(Database database, View view) { // Always update index if needed before querying (default) // Don't update the index; results may be out of date // Update index _after_ querying (results may still be out of date) // (the default), the query simply returns all non-deleted documents. // in this mode it also returns deleted documents. // the .conflictingRevisions property of each row will return the conflicting revisions, if any, of that document. // _only_ documents in conflict will be returned. (This mode is especially useful for use with a CBLLiveQuery, so you can be notified of conflicts as they happen, i.e. when they're pulled in by a replication.) // null for _all_docs query this.database = database; this.view = view; limit = int.MaxValue; mapOnly = (view != null && view.GetReduce() == null); indexUpdateMode = Query.IndexUpdateMode.Before; allDocsMode = Query.AllDocsMode.AllDocs; }