Skip to content

Commit

Permalink
Update sample
Browse files Browse the repository at this point in the history
  • Loading branch information
rickykaare committed Oct 11, 2024
1 parent 7f45bc4 commit ce65e88
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<PropertyGroup Label="Assembly Naming">
<Company>Cabazure</Company>
<Authors>Cabazure</Authors>
<Description>Library for creating .NET Clients for your AspNetCore REST APIs, using Source Generators directed by attributes.</Description>
<Description>Library for handling and executing Kusto scripts against an Azure Data Explorer cluster.</Description>
<NeutralLanguage>en</NeutralLanguage>
<DefaultLanguage>en-US</DefaultLanguage>
<DebugSymbols>true</DebugSymbols>
<DebugType>embedded</DebugType>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/Cabazure/Cabazure.Client</RepositoryUrl>
<RepositoryUrl>https://github.com/Cabazure/Cabazure.Kusto</RepositoryUrl>
</PropertyGroup>

<!-- Treat warnings as errors are always on when building in release -->
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,7 @@ app.MapGet(
The `maxItemCount` specifies how many items to return for each page. Each page is returned with a `continuationToken` that can be specified to fetch the next page.

The optional `sessionId` can be provided to optimize the use of storage on the ADX. If the same `sessionId` is specified for two calls they will share the underlying storage for pagination results.

## Sample

Please see the [SampleApi project](https://github.com/Cabazure/Cabazure.Kusto/tree/main/samples/SampleApi), for an example of how Cabazure.Kusto can be setup to query the "ContosoSales" database of the ADX sample cluster.
14 changes: 12 additions & 2 deletions samples/SampleApi/Contracts/Customer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
namespace SampleApi.Contracts;

public record Customer(
string CustomerKey,
string CustomerName);
int CustomerKey,
string FirstName,
string LastName,
string? CompanyName,
string CityName,
string StateProvinceName,
string RegionCountryName,
string ContinentName,
string Gender,
string MaritalStatus,
string Education,
string Occupation);
36 changes: 33 additions & 3 deletions samples/SampleApi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Azure.Identity;
using Cabazure.Kusto;
using Microsoft.AspNetCore.Mvc;
using SampleApi.Queries;

var builder = WebApplication.CreateBuilder(args);
Expand All @@ -24,9 +25,38 @@

app.UseHttpsRedirection();

app.MapGet("/customers", (IKustoProcessor processor, CancellationToken cancellationToken)
=> processor.ExecuteAsync(new CustomersQuery(), cancellationToken))
.WithName("GetCustomers")
app.MapGet(
"/customers",
async static (
[FromHeader(Name = "x-client-session-id")] string? sessionId,
[FromHeader(Name = "x-max-item-count")] int? maxItemCount,
[FromHeader(Name = "x-continuation-token")] string? continuationToken,
IKustoProcessor processor,
CancellationToken cancellationToken)
=> await processor.ExecuteAsync(
new CustomersQuery(),
sessionId,
maxItemCount ?? 100,
continuationToken,
cancellationToken))
.WithName("ListCustomers")
.WithOpenApi();

app.MapGet(
"/customers/{customerId}",
async static (
int customerId,
IKustoProcessor processor,
CancellationToken cancellationToken)
=> await processor.ExecuteAsync(
new CustomersQuery(
customerId),
cancellationToken) switch
{
[{ } customer] => Results.Ok(customer),
_ => Results.NotFound(),
})
.WithName("GetCustomer")
.WithOpenApi();

app.MapGet("/customer-sales", (IKustoProcessor processor, CancellationToken cancellationToken)
Expand Down
4 changes: 3 additions & 1 deletion samples/SampleApi/Queries/CustomersQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@

namespace SampleApi.Queries;

public record CustomersQuery : KustoQuery<Customer>;
public record CustomersQuery(
int? CustomerId = null)
: KustoQuery<Customer>;
18 changes: 16 additions & 2 deletions samples/SampleApi/Queries/CustomersQuery.kusto
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
Customers
declare query_parameters (
customerId:long = long(null)
);
Customers
| where isnull(customerId) or customerId == CustomerKey
| project
CustomerKey,
CustomerName = strcat(FirstName, ' ', LastName)
FirstName,
LastName,
CompanyName,
CityName,
StateProvinceName,
RegionCountryName,
ContinentName,
Gender,
MaritalStatus,
Education,
Occupation

0 comments on commit ce65e88

Please sign in to comment.