Skip to content

Commit

Permalink
feat: add support for explain prepared query API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
larrytamnjong committed Oct 2, 2024
1 parent b979d1e commit 9c2ec99
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions Consul/Interfaces/IPreparedQueryEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ public interface IPreparedQueryEndpoint
Task<WriteResult> Delete(string queryID, WriteOptions q, CancellationToken ct = default);
Task<QueryResult<PreparedQueryExecuteResponse>> Execute(string queryIDOrName, CancellationToken ct = default);
Task<QueryResult<PreparedQueryExecuteResponse>> Execute(string queryIDOrName, QueryOptions q, CancellationToken ct = default);
Task<QueryResult<PreparedQueryExplainResponse>> Explain(string queryIDOrName, QueryOptions q, CancellationToken ct = default);
}
}
21 changes: 21 additions & 0 deletions Consul/PreparedQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ public class PreparedQueryExecuteResponse
public int Failovers { get; set; }
}

public class PreparedQueryExplainResponse
{
/// <summary>
/// Query has the fully-rendered query.
/// </summary>
public PreparedQueryDefinition Query { get; set; }
}

public class PreparedQuery : IPreparedQueryEndpoint
{
private class PreparedQueryCreationResult
Expand Down Expand Up @@ -286,6 +294,19 @@ public Task<WriteResult> Update(PreparedQueryDefinition query, WriteOptions q, C
{
return _client.Put(string.Format("/v1/query/{0}", query.ID), query, q).Execute(ct);
}

/// <summary>
/// Shows which query a name resolves to, the fully interpolated template (if it's a template), as well as additional info about the execution of a query.
/// </summary>
/// <param name="queryIDOrName">Specifies the UUID of the query to explain. This can also be the name of an existing prepared query,
/// or a name that matches a prefix name for a prepared query template</param>
/// <param name="q">Query Options</param>
/// <param name="ct">Cancellation Token</param>
/// <returns>Returns a single prepared query</returns>
public Task<QueryResult<PreparedQueryExplainResponse>> Explain(string queryIDOrName, QueryOptions q, CancellationToken ct = default)
{
return _client.Get<PreparedQueryExplainResponse>(string.Format("/v1/query/{0}/explain", queryIDOrName), q).Execute(ct);
}
}

public partial class ConsulClient : IConsulClient
Expand Down

0 comments on commit 9c2ec99

Please sign in to comment.