VOOZH about

URL: https://www.nuget.org/packages/SurrealDb.Net/

⇱ NuGet Gallery | SurrealDb.Net 0.10.2




👁 Image
SurrealDb.Net 0.10.2

dotnet add package SurrealDb.Net --version 0.10.2
 
 
NuGet\Install-Package SurrealDb.Net -Version 0.10.2
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SurrealDb.Net" Version="0.10.2" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SurrealDb.Net" Version="0.10.2" />
 
Directory.Packages.props
<PackageReference Include="SurrealDb.Net" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SurrealDb.Net --version 0.10.2
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SurrealDb.Net, 0.10.2"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SurrealDb.Net@0.10.2
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SurrealDb.Net&version=0.10.2
 
Install as a Cake Addin
#tool nuget:?package=SurrealDb.Net&version=0.10.2
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

surrealdb.net

The official SurrealDB SDK for .NET.

Documentation

View the SDK documentation here.

How to install

dotnet add package SurrealDb.Net

Getting started

This library supports connecting to SurrealDB over the remote HTTP and WebSocket connection protocols http, https, ws, and wss.

The examples below require SurrealDB to be installed and running on port 8000.

Constructing a new SurrealDB client

You can easily create a new SurrealDB client. All you have to do is define the endpoint to the SurrealDB instance.

using var clientHttp = new SurrealDbClient("http://127.0.0.1:8000");
using var clientHttps = new SurrealDbClient("https://127.0.0.1:8000");
using var clientWs = new SurrealDbClient("ws://127.0.0.1:8000/rpc");
using var clientWss = new SurrealDbClient("wss://127.0.0.1:8000/rpc");

// Now you can call other methods including Signin & Use

Dependency injection

You can use Dependency Injection with the services.AddSurreal() function.

Default instance
var options = SurrealDbOptions
 .Create()
 .WithEndpoint("http://127.0.0.1:8000")
 .WithNamespace("test")
 .WithDatabase("test")
 .WithUsername("root")
 .WithPassword("root")
 .Build();

services.AddSurreal(options);

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);
Connection String

Consider the following appsettings.json file:

{
 "AllowedHosts": "*",
 "Logging": {
 "LogLevel": {
 "Default": "Information",
 "Microsoft.AspNetCore": "Warning"
 }
 },
 "ConnectionStrings": {
 "SurrealDB": "Server=http://127.0.0.1:8000;Namespace=test;Database=test;Username=root;Password=root"
 }
}

You can use the Connection String instead of having to deal with a SurrealDbOptions.

services.AddSurreal(configuration.GetConnectionString("SurrealDB"));

It will automatically create a new SurrealDB using the Server endpoint and configure the client using the different values for namespace, database, username and password. Note that these values are optional but the endpoint is still required.

Multiple instances

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"));
services.AddSurreal<IBackupSurrealDbClient>(configuration.GetConnectionString("SurrealDB.Backup"));
services.AddSurreal<IMonitoringSurrealDbClient>(configuration.GetConnectionString("SurrealDB.Monitoring"));

Here you will have 3 instances:

  • the default one, you can keep using ISurrealDbClient interface or SurrealDbClient class anywhere
  • a client for backup purpose, using the IBackupSurrealDbClient interface
  • a client for monitoring purpose, using the IMonitoringSurrealDbClient interface

Use the client

[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();
 }
}

Contributing

.NET release versions

The .NET release versions must follow these rules:

  • Should target at least the latest LTS (Long-Term Support) version
  • Should target at least the latest STS (Standard-Term Support) version

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

Formatting

This project is using CSharpier, an opinionated code formatter.

Command line

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

IDE integration

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 net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 was computed.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  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. 
.NET Core netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 netstandard2.1 is compatible. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (9)

Showing the top 5 NuGet packages that depend on SurrealDb.Net:

Package Downloads
CommunityToolkit.Aspire.Hosting.SurrealDb

SurrealDB support for Aspire.

CommunityToolkit.Aspire.SurrealDb

A SurrealDB client that integrates with Aspire, including health checks, logging, and telemetry.

AspNetCore.HealthChecks.SurrealDb

HealthChecks.SurrealDb is the health check package for SurrealDB.

CloudTheWolf.DSharpPlus.Scaffolding.Data

Database System for CloudTheWolf.DSharpPlus.Scaffolding

SurrealDb.Reactive

Reactive Extensions for the SurrealDB library for .NET

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on SurrealDb.Net:

Repository Stars
Xabaril/AspNetCore.Diagnostics.HealthChecks
Enterprise HealthChecks for ASP.NET Core Diagnostics Package
CommunityToolkit/Aspire
A community project with additional components and extensions for Aspire
Version Downloads Last Updated
0.10.2 1,694 4/24/2026
0.9.0 23,604 7/25/2025
0.8.0 4,253 3/28/2025
0.7.0 15,354 12/12/2024
0.6.0 1,741 10/21/2024
0.5.1 4,200 7/12/2024
0.5.0 11,153 4/4/2024
0.4.0 1,037 2/8/2024
0.3.1 639 1/19/2024
0.2.0 2,532 11/21/2023
0.1.4 5,576 10/25/2023
0.1.3 780 9/25/2023