Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
Hosting.Dapr.Tests,
Hosting.DbGate.Tests,
Hosting.Deno.Tests,
Hosting.DuckDB.Tests,
Hosting.Elasticsearch.Extensions.Tests,
Hosting.Flagd.Tests,
Hosting.Flyway.Tests,
Expand Down Expand Up @@ -68,6 +69,7 @@ jobs:
Hosting.Zitadel.Tests,

# Client integration tests
DuckDB.NET.Data.Tests,
GoFeatureFlag.Tests,
KurrentDB.Tests,
MassTransit.RabbitMQ.Tests,
Expand Down
9 changes: 9 additions & 0 deletions CommunityToolkit.Aspire.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<Folder Name="/examples/deno/">
<Project Path="examples/deno/CommunityToolkit.Aspire.Hosting.Deno.AppHost/CommunityToolkit.Aspire.Hosting.Deno.AppHost.csproj" />
</Folder>
<Folder Name="/examples/duckdb/">
<Project Path="examples/duckdb/CommunityToolkit.Aspire.DuckDB.Api/CommunityToolkit.Aspire.DuckDB.Api.csproj" />
<Project Path="examples/duckdb/CommunityToolkit.Aspire.DuckDB.AppHost/CommunityToolkit.Aspire.DuckDB.AppHost.csproj" />
<Project Path="examples/duckdb/CommunityToolkit.Aspire.DuckDB.ServiceDefaults/CommunityToolkit.Aspire.DuckDB.ServiceDefaults.csproj" />
</Folder>
<Folder Name="/examples/elasticsearch-ext/">
<Project Path="examples/elasticsearch-ext/CommunityToolkit.Aspire.Hosting.Elasticsearch.Extensions.AppHost/CommunityToolkit.Aspire.Hosting.Elasticsearch.Extensions.AppHost.csproj" />
</Folder>
Expand Down Expand Up @@ -204,6 +209,7 @@
<Project Path="src/CommunityToolkit.Aspire.Hosting.Bun/CommunityToolkit.Aspire.Hosting.Bun.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.DbGate/CommunityToolkit.Aspire.Hosting.DbGate.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.Deno/CommunityToolkit.Aspire.Hosting.Deno.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.DuckDB/CommunityToolkit.Aspire.Hosting.DuckDB.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.Elasticsearch.Extensions/CommunityToolkit.Aspire.Hosting.Elasticsearch.Extensions.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.Flagd/CommunityToolkit.Aspire.Hosting.Flagd.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.Flyway/CommunityToolkit.Aspire.Hosting.Flyway.csproj" />
Expand Down Expand Up @@ -238,6 +244,7 @@
<Project Path="src/CommunityToolkit.Aspire.Hosting.Stripe/CommunityToolkit.Aspire.Hosting.Stripe.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.SurrealDb/CommunityToolkit.Aspire.Hosting.SurrealDb.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Hosting.Zitadel/CommunityToolkit.Aspire.Hosting.Zitadel.csproj" />
<Project Path="src/CommunityToolkit.Aspire.DuckDB.NET.Data/CommunityToolkit.Aspire.DuckDB.NET.Data.csproj" />
<Project Path="src/CommunityToolkit.Aspire.KurrentDB/CommunityToolkit.Aspire.KurrentDB.csproj" />
<Project Path="src/CommunityToolkit.Aspire.MassTransit.RabbitMQ/CommunityToolkit.Aspire.MassTransit.RabbitMQ.csproj" />
<Project Path="src/CommunityToolkit.Aspire.Meilisearch/CommunityToolkit.Aspire.Meilisearch.csproj" />
Expand Down Expand Up @@ -265,6 +272,7 @@
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Bun.Tests/CommunityToolkit.Aspire.Hosting.Bun.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.DbGate.Tests/CommunityToolkit.Aspire.Hosting.DbGate.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Deno.Tests/CommunityToolkit.Aspire.Hosting.Deno.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.DuckDB.Tests/CommunityToolkit.Aspire.Hosting.DuckDB.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Elasticsearch.Extensions.Tests/CommunityToolkit.Aspire.Hosting.Elasticsearch.Extensions.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Flagd.Tests/CommunityToolkit.Aspire.Hosting.Flagd.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Flyway.Tests/CommunityToolkit.Aspire.Hosting.Flyway.Tests.csproj" />
Expand Down Expand Up @@ -299,6 +307,7 @@
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Stripe.Tests/CommunityToolkit.Aspire.Hosting.Stripe.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.SurrealDb.Tests/CommunityToolkit.Aspire.Hosting.SurrealDb.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Zitadel.Tests/CommunityToolkit.Aspire.Hosting.Zitadel.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.DuckDB.NET.Data.Tests/CommunityToolkit.Aspire.DuckDB.NET.Data.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.KurrentDB.Tests/CommunityToolkit.Aspire.KurrentDB.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.MassTransit.RabbitMQ.Tests/CommunityToolkit.Aspire.MassTransit.RabbitMQ.Tests.csproj" />
<Project Path="tests/CommunityToolkit.Aspire.Meilisearch.Tests/CommunityToolkit.Aspire.Meilisearch.Tests.csproj" />
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<PackageVersion Include="MassTransit.ActiveMQ" Version="8.5.5" />
<PackageVersion Include="MassTransit.RabbitMQ" Version="8.5.5" />
<PackageVersion Include="MeiliSearch" Version="0.18.0" />
<PackageVersion Include="DuckDB.NET.Data.Full" Version="1.5.0" />
<PackageVersion Include="Microsoft.Data.Sqlite" Version="10.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.2" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="$(DotNetExtensionsVersion)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<ItemGroup>
<ProjectReference Include="../../../src/CommunityToolkit.Aspire.DuckDB.NET.Data/CommunityToolkit.Aspire.DuckDB.NET.Data.csproj" />
<ProjectReference Include="../CommunityToolkit.Aspire.DuckDB.ServiceDefaults/CommunityToolkit.Aspire.DuckDB.ServiceDefaults.csproj" />
</ItemGroup>

</Project>
123 changes: 123 additions & 0 deletions examples/duckdb/CommunityToolkit.Aspire.DuckDB.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using DuckDB.NET.Data;

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();
builder.Services.AddProblemDetails();

builder.AddDuckDBConnection("analytics");

var app = builder.Build();
app.UseExceptionHandler();
app.MapDefaultEndpoints();

await SeedDatabase(app);

app.MapGet("/", () => "DuckDB Analytics API");

var analyticsGroup = app.MapGroup("/analytics");

analyticsGroup.MapGet("/summary", async (DuckDBConnection db) =>
{
await db.OpenAsync();
using var command = db.CreateCommand();
command.CommandText = """
SELECT
category,
COUNT(*) as total_orders,
CAST(SUM(amount) AS DOUBLE) as total_revenue,
CAST(AVG(amount) AS DOUBLE) as avg_order_value
FROM orders
GROUP BY category
ORDER BY total_revenue DESC
""";
using var reader = await command.ExecuteReaderAsync();

var results = new List<object>();
while (await reader.ReadAsync())
{
results.Add(new
{
Category = reader.GetString(0),
TotalOrders = reader.GetInt64(1),
TotalRevenue = reader.GetDouble(2),
AvgOrderValue = reader.GetDouble(3)
});
}
return Results.Ok(results);
});

analyticsGroup.MapPost("/orders", async (DuckDBConnection db) =>
{
await db.OpenAsync();
using var command = db.CreateCommand();
command.CommandText = """
INSERT INTO orders (category, product, amount, order_date) VALUES
('Electronics', 'Laptop', 999.99, CURRENT_TIMESTAMP)
""";
await command.ExecuteNonQueryAsync();
return Results.Created("/analytics/summary", null);
});

analyticsGroup.MapGet("/orders", async (DuckDBConnection db) =>
{
await db.OpenAsync();
using var command = db.CreateCommand();
command.CommandText = "SELECT id, category, product, amount, order_date FROM orders ORDER BY order_date DESC LIMIT 100";
using var reader = await command.ExecuteReaderAsync();

var results = new List<object>();
while (await reader.ReadAsync())
{
results.Add(new
{
Id = reader.GetInt32(0),
Category = reader.GetString(1),
Product = reader.GetString(2),
Amount = reader.GetDouble(3),
OrderDate = reader.GetDateTime(4)
});
}
return Results.Ok(results);
});

app.Run();

static async Task SeedDatabase(WebApplication app)
{
using var scope = app.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<DuckDBConnection>();
await db.OpenAsync();

using var createCommand = db.CreateCommand();
createCommand.CommandText = """
CREATE SEQUENCE IF NOT EXISTS orders_id_seq START 1;
CREATE TABLE IF NOT EXISTS orders (
id INTEGER DEFAULT nextval('orders_id_seq'),
category VARCHAR,
product VARCHAR,
amount DOUBLE,
order_date TIMESTAMP
)
""";
await createCommand.ExecuteNonQueryAsync();

// Check if data already exists
using var countCommand = db.CreateCommand();
countCommand.CommandText = "SELECT COUNT(*) FROM orders";
var count = (long)(await countCommand.ExecuteScalarAsync())!;

if (count == 0)
{
using var seedCommand = db.CreateCommand();
seedCommand.CommandText = """
INSERT INTO orders (id, category, product, amount, order_date) VALUES
(1, 'Electronics', 'Laptop', 1299.99, '2025-01-15 10:30:00'),
(2, 'Electronics', 'Phone', 899.99, '2025-01-16 14:20:00'),
(3, 'Books', 'Programming Guide', 49.99, '2025-01-17 09:15:00'),
(4, 'Books', 'Data Science Manual', 59.99, '2025-01-18 11:45:00'),
(5, 'Clothing', 'T-Shirt', 29.99, '2025-01-19 16:00:00')
""";
await seedCommand.ExecuteNonQueryAsync();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5301",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7301;http://localhost:5301",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Aspire.AppHost.Sdk/13.2.0">

<PropertyGroup>
<OutputType>Exe</OutputType>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>duckdb-apphost-secrets</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../../src/CommunityToolkit.Aspire.Hosting.DuckDB/CommunityToolkit.Aspire.Hosting.DuckDB.csproj" IsAspireProjectResource="False" />
<ProjectReference Include="../CommunityToolkit.Aspire.DuckDB.Api/CommunityToolkit.Aspire.DuckDB.Api.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var builder = DistributedApplication.CreateBuilder(args);

var duckdb = builder.AddDuckDB("analytics");

var api = builder.AddProject<Projects.CommunityToolkit_Aspire_DuckDB_Api>("api")
.WithReference(duckdb);

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17280;http://localhost:15176",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21290",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22189"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15176",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19099",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20223"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<IsAspireSharedProject>true</IsAspireSharedProject>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />

<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" />
</ItemGroup>

</Project>
Loading