/// <summary> /// Performs the REMOVE operation on a frame stream /// </summary> public IEnumerable <ExecutionFrame> ApplyToFrameStream( QueryExecutor executor, IEnumerable <ExecutionFrame> frameStream ) { foreach (ExecutionFrame frame in frameStream) { JsonValue keyResult = KeyExpression.Evaluate(executor, frame); // get key & ref string key; string rev; if (keyResult.IsJsonObject) { key = keyResult["_key"].AsString; rev = keyResult["_rev"].AsString; } else { key = keyResult.AsString; rev = null; } // OLD JsonObject oldDocument = executor.DataSource.GetDocument( CollectionName, key ); // remove executor.DataSource.RemoveDocument( CollectionName, key, rev, Options ); // update frame yield return(frame .AddVariable("OLD", oldDocument)); } }
/// <summary> /// Performs the REPLACE operation on a frame stream /// </summary> public IEnumerable <ExecutionFrame> ApplyToFrameStream( QueryExecutor executor, IEnumerable <ExecutionFrame> frameStream ) { foreach (ExecutionFrame frame in frameStream) { // get key JsonValue keyResult = KeyExpression.Evaluate(executor, frame); string key = keyResult.AsString; if (keyResult.IsJsonObject) { key = keyResult["_key"].AsString; } // get document JsonObject document = keyResult; if (WithExpression != null) { document = WithExpression.Evaluate(executor, frame); } // OLD JsonObject oldDocument = executor.DataSource.GetDocument( CollectionName, key ); // replace & NEW JsonObject newDocument = executor.DataSource.ReplaceDocument( CollectionName, key, document, Options ); // update frame yield return(frame .AddVariable("OLD", oldDocument) .AddVariable("NEW", newDocument)); } }