/// <summary> /// Queries the specified view using the specified options /// </summary> /// <returns>The HTTP response containing the results of the query</returns> /// <param name="context">The request context</param> /// <param name="view">The view to query</param> /// <param name="options">The options to apply to the query</param> public static CouchbaseLiteResponse QueryView(ICouchbaseListenerContext context, Database db, View view, QueryOptions options) { var result = view.QueryWithOptions(options); object updateSeq = options.UpdateSeq ? (object)view.LastSequenceIndexed : null; var mappedResult = new List <object>(); foreach (var row in result) { row.Database = db; var dict = row.AsJSONDictionary(); if (context.ContentOptions != DocumentContentOptions.None) { var doc = dict.Get("doc").AsDictionary <string, object>(); if (doc != null) { // Add content options: RevisionInternal rev = new RevisionInternal(doc); var status = new Status(); rev = DocumentMethods.ApplyOptions(context.ContentOptions, rev, context, db, status); if (rev != null) { dict["doc"] = rev.GetProperties(); } } } mappedResult.Add(dict); } var body = new Body(new NonNullDictionary <string, object> { { "rows", mappedResult }, { "total_rows", view.TotalRows }, { "offset", options.Skip }, { "update_seq", updateSeq } }); var retVal = context.CreateResponse(); retVal.JsonBody = body; return(retVal); }
/// <summary> /// Creates a dictionary of metadata for one specific revision /// </summary> /// <returns>The metadata dictionary</returns> /// <param name="rev">The revision to examine</param> /// <param name="responseState">The current response state</param> public static IDictionary <string, object> ChangesDictForRev(RevisionInternal rev, DBMonitorCouchbaseResponseState responseState) { if (responseState.ChangesIncludeDocs) { var status = new Status(); var rev2 = DocumentMethods.ApplyOptions(responseState.ContentOptions, rev, responseState.Context, responseState.Db, status); if (rev2 != null) { rev2.SetSequence(rev.GetSequence()); rev = rev2; } } return(new NonNullDictionary <string, object> { { "seq", rev.GetSequence() }, { "id", rev.GetDocId() }, { "changes", new List <object> { new Dictionary <string, object> { { "rev", rev.GetRevId() } } } }, { "deleted", rev.IsDeleted() ? (object)true : null }, { "doc", responseState.ChangesIncludeDocs ? rev.GetProperties() : null } }); }