![]() |
VOOZH | about |
dotnet add package SurrealDb.Embedded.InMemory --version 0.10.2
NuGet\Install-Package SurrealDb.Embedded.InMemory -Version 0.10.2
<PackageReference Include="SurrealDb.Embedded.InMemory" Version="0.10.2" />
<PackageVersion Include="SurrealDb.Embedded.InMemory" Version="0.10.2" />Directory.Packages.props
<PackageReference Include="SurrealDb.Embedded.InMemory" />Project file
paket add SurrealDb.Embedded.InMemory --version 0.10.2
#r "nuget: SurrealDb.Embedded.InMemory, 0.10.2"
#:package SurrealDb.Embedded.InMemory@0.10.2
#addin nuget:?package=SurrealDb.Embedded.InMemory&version=0.10.2Install as a Cake Addin
#tool nuget:?package=SurrealDb.Embedded.InMemory&version=0.10.2Install as a Cake Tool
In-memory provider of the official SurrealDB SDK for .NET.
View the SDK documentation here.
dotnet add package SurrealDb.Embedded.InMemory
You can easily create a new SurrealDB memory client which will provide an in-memory instance of SurrealDB.
using var db = new SurrealDbMemoryClient();
const string TABLE = "person";
var person = new Person
{
Title = "Founder & CEO",
Name = new() { FirstName = "Tobie", LastName = "Morgan Hitchcock" },
Marketing = true
};
var created = await db.Create(TABLE, person);
Console.WriteLine(ToJsonString(created));
You can use Dependency Injection with the services.AddSurreal() and .AddInMemoryProvider() functions.
services.
.AddSurreal("Endpoint=mem://")
.AddInMemoryProvider();
Then you will be able to use the ISurrealDbClient interface or SurrealDbClient class anywhere.
public class MyClass
{
private readonly ISurrealDbClient _client;
public MyClass(ISurrealDbClient client)
{
_client = client;
}
// ...
}
Note that the default lifetime of this service is Scoped. You can override this as follows:
services.AddSurreal(options, ServiceLifetime.Scoped);
Consider the following appsettings.json file:
{
"AllowedHosts": "*",
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"SurrealDB": "Endpoint=mem://;Namespace=test;Database=test"
}
}
You can use the Connection String instead of having to deal with a SurrealDbOptions.
services
.AddSurreal(configuration.GetConnectionString("SurrealDB"))
.AddInMemoryProvider();
It will automatically create a new SurrealDB using the Client endpoint and configure the client using the different values for namespace, database. Note that these values are optional but the endpoint is still required.
Having a default instance for a project is enough most of the time, but there may be times when you'd like to target multiple SurrealDB instances, either at different addresses or at the same address but inside different NS/DBs. You can use multiple instances as long as you provide 1 interface per client, as in the following example.
interface IBackupSurrealDbClient : ISurrealDbClient { }
interface IMonitoringSurrealDbClient : ISurrealDbClient { }
services
.AddSurreal(configuration.GetConnectionString("SurrealDB.Main"))
.AddInMemoryProvider();
services.AddSurreal<IBackupSurrealDbClient>(configuration.GetConnectionString("SurrealDB.Backup"));
services.AddSurreal<IMonitoringSurrealDbClient>(configuration.GetConnectionString("SurrealDB.Monitoring"));
Here you will have 3 instances:
ISurrealDbClient interface or SurrealDbClient class anywhereIBackupSurrealDbClient interfaceIMonitoringSurrealDbClient interface[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private const string Table = "weatherForecast";
private readonly ISurrealDbClient _surrealDbClient;
public WeatherForecastController(ISurrealDbClient surrealDbClient)
{
_surrealDbClient = surrealDbClient;
}
[HttpGet]
public Task<IEnumerable<WeatherForecast>> GetAll(CancellationToken cancellationToken)
{
return _surrealDbClient.Select<WeatherForecast>(Table, cancellationToken);
}
[HttpGet("{id}")]
public async Task<IActionResult> Get(string id, CancellationToken cancellationToken)
{
var weatherForecast = await _surrealDbClient.Select<WeatherForecast>((Table, id), cancellationToken);
if (weatherForecast is null)
return NotFound();
return Ok(weatherForecast);
}
[HttpPost]
public Task<WeatherForecast> Create(CreateWeatherForecast data, CancellationToken cancellationToken)
{
var weatherForecast = new WeatherForecast
{
Date = data.Date,
Country = data.Country,
TemperatureC = data.TemperatureC,
Summary = data.Summary
};
return _surrealDbClient.Create(Table, weatherForecast, cancellationToken);
}
[HttpPut]
public Task<WeatherForecast> Update(WeatherForecast data, CancellationToken cancellationToken)
{
return _surrealDbClient.Upsert(data, cancellationToken);
}
[HttpPatch]
public Task<IEnumerable<WeatherForecast>> PatchAll(
JsonPatchDocument<WeatherForecast> patches,
CancellationToken cancellationToken
)
{
return _surrealDbClient.PatchAll(Table, patches, cancellationToken);
}
[HttpPatch("{id}")]
public Task<WeatherForecast> Patch(
string id,
JsonPatchDocument<WeatherForecast> patches,
CancellationToken cancellationToken
)
{
return _surrealDbClient.Patch((Table, id), patches, cancellationToken);
}
[HttpDelete]
public Task DeleteAll(CancellationToken cancellationToken)
{
return _surrealDbClient.Delete(Table, cancellationToken);
}
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(string id, CancellationToken cancellationToken)
{
bool success = await _surrealDbClient.Delete((Table, id), cancellationToken);
if (!success)
return NotFound();
return Ok();
}
}
The .NET release versions must follow these rules:
SurrealDb.Net targets .NET versions following the .NET Support Policy by Microsoft. Additionally, SurrealDb.Net targets .NET Standard 2.1 explicitly to continue support of the Mono runtime (Unity, Xamarin, etc...).
Note that the support for .NET standard 2.1 will be maintained until further notice.
| Version | Description | Release Date | End of Support |
|---|---|---|---|
| .NET Standard 2.1 | June 27, 2016 | N/A | |
| .NET 8 | LTS | November 14, 2023 | November 10, 2026 |
| .NET 9 | STS | November 12, 2024 | November 10, 2026 |
| .NET 10 | Current LTS | November 11, 2025 | November 14, 2028 |
This project is using CSharpier, an opinionated code formatter.
You can install it on your machine via dotnet tool.
# Run this command at the root of the project
dotnet tool install csharpier
You can then use it as a cli:
dotnet csharpier .
The list of command-line options is available here: https://csharpier.com/docs/CLI
CSharpier supports multiple code editors, including Visual Studio, Jetbrains Rider, VSCode and Neovim. You will be able to run format on file save after configuring the settings in your IDE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.