-
Notifications
You must be signed in to change notification settings - Fork 110
Add SurrealDB hosting/client integration #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fc44c8e
feat: add surrealdb hosting/client integration
Odonno 4c33d45
docs: update readme
Odonno 3b3726c
docs: create example projects
Odonno ec8e53c
test: add tests for surrealdb integration
Odonno 9b181ff
chore: set code owners for SurrealDB integration
Odonno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
....Hosting.SurrealDb.ApiService/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
Odonno marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.SurrealDb\CommunityToolkit.Aspire.SurrealDb.csproj" /> | ||
<ProjectReference Include="..\CommunityToolkit.Aspire.Hosting.SurrealDb.ServiceDefaults\CommunityToolkit.Aspire.Hosting.SurrealDb.ServiceDefaults.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Bogus" /> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" /> | ||
<PackageReference Include="SurrealDb.MinimalApis.Extensions" /> | ||
</ItemGroup> | ||
|
||
</Project> |
12 changes: 12 additions & 0 deletions
12
examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/Todo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using SurrealDb.Net.Models; | ||
|
||
namespace CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService.Models; | ||
|
||
public class Todo : Record | ||
{ | ||
internal const string Table = "todo"; | ||
|
||
public string? Title { get; set; } | ||
public DateOnly? DueBy { get; set; } = null; | ||
public bool IsComplete { get; set; } = false; | ||
} |
36 changes: 36 additions & 0 deletions
36
.../surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/WeatherForecast.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using SurrealDb.Net.Models; | ||
|
||
namespace CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService.Models; | ||
|
||
/// <summary> | ||
/// Weather forecast model. | ||
/// </summary> | ||
public class WeatherForecast : Record | ||
{ | ||
internal const string Table = "weatherForecast"; | ||
|
||
/// <summary> | ||
/// Date of the weather forecast. | ||
/// </summary> | ||
public DateTime Date { get; set; } | ||
|
||
/// <summary> | ||
/// Country of the weather forecast. | ||
/// </summary> | ||
public string? Country { get; set; } | ||
|
||
/// <summary> | ||
/// Temperature in Celsius. | ||
/// </summary> | ||
public int TemperatureC { get; set; } | ||
|
||
/// <summary> | ||
/// Temperature in Fahrenheit. | ||
/// </summary> | ||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
|
||
/// <summary> | ||
/// Summary of the weather forecast. | ||
/// </summary> | ||
public string? Summary { get; set; } | ||
} |
34 changes: 34 additions & 0 deletions
34
...ealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Models/WeatherForecastFaker.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Bogus; | ||
|
||
namespace CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService.Models; | ||
|
||
/// <summary> | ||
/// Faker test class to generate fake WeatherForecast objects. | ||
/// </summary> | ||
public class WeatherForecastFaker : Faker<WeatherForecast> | ||
{ | ||
private static readonly string[] Summaries = new[] | ||
{ | ||
"Freezing", | ||
"Bracing", | ||
"Chilly", | ||
"Cool", | ||
"Mild", | ||
"Warm", | ||
"Balmy", | ||
"Hot", | ||
"Sweltering", | ||
"Scorching" | ||
}; | ||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
public WeatherForecastFaker() | ||
{ | ||
RuleFor(o => o.Date, f => f.Date.Recent()); | ||
RuleFor(o => o.Country, f => f.Address.Country()); | ||
RuleFor(o => o.TemperatureC, f => f.Random.Number(-20, 55)); | ||
RuleFor(o => o.Summary, f => f.Random.ArrayElement(Summaries)); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService.Models; | ||
using SurrealDb.Net; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.AddServiceDefaults(); | ||
|
||
builder.AddSurrealClient("db", settings => | ||
{ | ||
// TODO : Wait for v0.7 | ||
// settings.Options!.NamingPolicy = "CamelCase"; | ||
}); | ||
|
||
var app = builder.Build(); | ||
|
||
app.MapDefaultEndpoints(); | ||
|
||
app.MapGroup("/api") | ||
.MapSurrealEndpoints<WeatherForecast>( | ||
"/weatherForecast", | ||
new() { EnableMutations = false } | ||
) | ||
.MapSurrealEndpoints<Todo>("/todo"); | ||
|
||
app.MapPost("/init", InitializeDbAsync); | ||
|
||
app.Run(); | ||
|
||
Task InitializeDbAsync(ISurrealDbClient surrealDbClient) | ||
{ | ||
const int initialCount = 5; | ||
var weatherForecasts = new WeatherForecastFaker().Generate(initialCount); | ||
|
||
var tasks = weatherForecasts.Select(weatherForecast => | ||
surrealDbClient.Create(WeatherForecast.Table, weatherForecast) | ||
); | ||
|
||
return Task.WhenAll(tasks); | ||
} |
23 changes: 23 additions & 0 deletions
23
...ealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:5284", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:7079;http://localhost:5284", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService/appsettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
21 changes: 21 additions & 0 deletions
21
...Aspire.Hosting.SurrealDb.AppHost/CommunityToolkit.Aspire.Hosting.SurrealDb.AppHost.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Sdk Name="Aspire.AppHost.Sdk" Version="$(AspireAppHostSdkVersion)"/> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
Odonno marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsAspireHost>true</IsAspireHost> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Aspire.Hosting.AppHost" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.SurrealDb\CommunityToolkit.Aspire.Hosting.SurrealDb.csproj" IsAspireProjectResource="false" /> | ||
<ProjectReference Include="..\CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService\CommunityToolkit.Aspire.Hosting.SurrealDb.ApiService.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
13 changes: 13 additions & 0 deletions
13
examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.AppHost/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Projects; | ||
|
||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var db = builder.AddSurrealServer("surreal") | ||
.AddNamespace("ns") | ||
.AddDatabase("db"); | ||
|
||
builder.AddProject<CommunityToolkit_Aspire_Hosting_SurrealDb_ApiService>("apiservice") | ||
.WithReference(db) | ||
.WaitFor(db); | ||
|
||
builder.Build().Run(); |
29 changes: 29 additions & 0 deletions
29
...urrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.AppHost/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:11918;http://localhost:37012", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:31745", | ||
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:12787" | ||
} | ||
}, | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "http://localhost:15730", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19870", | ||
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20522" | ||
} | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
examples/surrealdb/CommunityToolkit.Aspire.Hosting.SurrealDb.AppHost/appsettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the CODEOWNERS to be valid you would need to join the maintainer group - is that something you're interested in (I'm guessing so since you put yourself down as the owner 😉)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be good now. Can you reopen the PR @aaronpowell ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aaronpowell ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aaronpowell Are you there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unable to reopen the PR, looks like the branch has had a force push done since it was closed so the PR isn't able to reopen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I opened a new PR #365