public override async Task Process(TSqlCommand pipe) { if (this.countOnly) { await pipe.Sql(cmd).Stream(response.Body, "-1"); } else if (metadata == Metadata.NONE) { response.ContentType = "application/json;odata.metadata=none;odata=nometadata"; await pipe .Sql(cmd) .OnError(async e => await ReturnClientError(response, e)) .Stream(response.Body, IsSingletonResponse ? "{}" : "{\"value\":[]}"); } else if (metadata == Metadata.MINIMAL) { response.ContentType = "application/json;odata.metadata=minimal"; var header = "{\"@odata.context\":\"" + this.metadataUrl + "#" + this.tableSpec.Name + "\",\"value\":"; await pipe .Sql(cmd) .OnError(async e => await ReturnClientError(response, e)) .Stream(response.Body, new Options() { Prefix = header, DefaultOutput = "[]", Suffix = "}" }); } else { await ReturnClientError(response, new InvalidOperationException("Cannot generate response for metadata type: " + metadata)); } }
/// <summary> /// Created IActionResult object that contains the processed response result. /// </summary> /// <param name="pipe">Sql Pipe that will be used to fetch the data.</param> /// <returns>ContentResult with the data processed by request.</returns> public virtual Task <string> GetString(TSqlCommand mapper) { var res = mapper .Sql(cmd) .GetString(); return(res); }
/// <summary> /// Process the current request and returns result using the target database. /// </summary> /// <param name="pipe">Sql Pipe that will be used to fetch the data.</param> /// <returns>Async task that will stream results.</returns> public virtual async Task Process(TSqlCommand pipe) { response.ContentType = "application/json"; await pipe.Sql(cmd) .OnError(async e => await ReturnClientError(response, e)) .Stream(response.Body, IsSingletonResponse?"{}":"[]") .ConfigureAwait(false); }