Path: redb-route/redb.Route.Sql/SqlExchangeHeaders.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Sql/SqlExchangeHeaders.cs
----
using redb.Route.Abstractions;
using redb.Route.Expressions;
namespace redb.Route.Sql;
/// Headers every SQL producer path writes after it ran a statement.
internal static class SqlExchangeHeaders
{
///
/// The header outputHeader names on this exchange: the option as written, or — when it is a ${...}
/// expression — its value on the exchange.
///
/// The expression yields no name.
internal static string ResolveOutputHeader(string outputHeader, IExchange exchange)
{
if (!outputHeader.Contains("${", StringComparison.Ordinal))
return outputHeader;
var name = ExpressionResolver.ResolveTypedOrTemplate(outputHeader, exchange)?.ToString();
if (string.IsNullOrEmpty(name))
throw new InvalidOperationException($"outputHeader '{outputHeader}' yields no header name on this exchange.");
return name;
}
///
/// Writes query text, execution time, data source and output type — the type the statement resolved to when
/// is given (Auto becomes what the driver returned), the option otherwise.
///
internal static void SetCommon(
IExchange exchange, SqlEndpointOptions options, string sql, long executionMs, SqlOutputType? resolvedOutputType = null)
{
exchange.In.Headers[SqlHeaders.Query] = sql;
exchange.In.Headers[SqlHeaders.ExecutionTime] = executionMs;
if (options.DataSource != null)
exchange.In.Headers[SqlHeaders.DataSource] = options.DataSource;
exchange.In.Headers[SqlHeaders.OutputType] = (resolvedOutputType ?? options.OutputType).ToString();
}
}