### Starting Local SurrealDB Instance for Benchmarking Source: https://github.com/surrealdb/surrealdb.net/blob/main/README.md Starts a local SurrealDB instance in memory mode with root user credentials, specifically for running performance benchmarks. This setup ensures a consistent environment for measurements. ```sh surreal start --user root --pass root memory --allow-guests ``` -------------------------------- ### Starting Local SurrealDB Instance Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net.Benchmarks.Embedded/README.md This command initiates a local SurrealDB instance, configuring it with 'root' user credentials and enabling guest access. This setup is a prerequisite for executing the embedded benchmarks. ```sh surreal start --user root --pass root memory --allow-guests ``` -------------------------------- ### Starting Local SurrealDB Instance for Testing Source: https://github.com/surrealdb/surrealdb.net/blob/main/README.md Initiates a local SurrealDB instance in memory mode with debug logging enabled, and root user credentials. This setup is a prerequisite for running the project's integration tests. ```sh surreal start --log debug --user root --pass root memory --allow-guests ``` -------------------------------- ### Starting SurrealDB Local Instance (Shell) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Examples.MinimalApis/README.md This command starts a local SurrealDB server instance with debug logging enabled, using 'root' for both username and password, and allowing guest connections. It configures the database to run in memory. ```sh surreal start --log debug --user root --pass root memory --allow-guests ``` -------------------------------- ### Running .NET Application (Shell) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Examples.TodoApi.Aot/README.md This command executes the .NET application from the command line. It's used to launch the TodoApi example, which then connects to the previously started SurrealDB server, making its API endpoints available for data retrieval. ```sh dotnet run ``` -------------------------------- ### Installing SurrealDb.Reactive Package - Shell Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Reactive/README.md This command installs the SurrealDb.Reactive NuGet package into your .NET project, enabling the use of Reactive Extensions with the SurrealDB SDK. ```Shell dotnet add package SurrealDb.Reactive ``` -------------------------------- ### Installing CSharpier CLI Tool - Shell Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Reactive/README.md This command installs CSharpier as a .NET local tool, making it available for use from the command line within the project directory for code formatting. ```Shell dotnet tool install csharpier ``` -------------------------------- ### Installing CSharpier .NET Tool Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net.LiveQuery.Tests/README.md This command installs CSharpier as a .NET local tool. It should be run from the root directory of the project to enable code formatting. ```sh dotnet tool install csharpier ``` -------------------------------- ### Starting Local SurrealDB Instance (Shell) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Examples.WeatherApi/README.md This command starts a local SurrealDB server instance. It configures logging to debug level, sets the root user credentials, specifies 'memory' as the storage backend, and allows guest access for development purposes. ```sh surreal start --log debug --user root --pass root memory --allow-guests ``` -------------------------------- ### Installing CSharpier .NET Tool Source: https://github.com/surrealdb/surrealdb.net/blob/main/README.md This command installs CSharpier as a global .NET tool, enabling its use for consistent code formatting across the project. It should be run from the root directory of the project. ```sh dotnet tool install csharpier ``` -------------------------------- ### Installing CSharpier .NET Tool Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.MinimalApis.Extensions/README.md This command installs CSharpier as a .NET local tool. CSharpier is an opinionated code formatter used in this project to maintain consistent code style. It should be run from the root directory of the project. ```sh # Run this command at the root of the project dotnet tool install csharpier ``` -------------------------------- ### Installing SurrealDB Minimal APIs Extensions Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.MinimalApis.Extensions/README.md This snippet provides the necessary `dotnet add package` commands to install the SurrealDb.MinimalApis.Extensions, SurrealDb.Net, and Microsoft.AspNetCore.OpenApi packages. These packages are prerequisites for using SurrealDB with ASP.NET Core Minimal APIs. ```sh dotnet add package SurrealDb.MinimalApis.Extensions dotnet add package SurrealDb.Net dotnet add package Microsoft.AspNetCore.OpenApi ``` -------------------------------- ### Starting SurrealDB Local Instance (Shell) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Examples.TodoApi.Aot/README.md This shell command initializes and starts a local SurrealDB server instance. It configures the server to run in debug mode, sets the username and password to 'root', uses an in-memory database, and allows guest connections for easy testing. ```sh surreal start --log debug --user root --pass root memory --allow-guests ``` -------------------------------- ### Starting SurrealDB Local Instance (Shell) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Examples.Blazor.Server/README.md This command initiates a local SurrealDB server instance. It configures debug logging, sets the 'root' user and password, uses in-memory storage for data, and permits guest connections, which is suitable for development environments. ```Shell surreal start --log debug --user root --pass root memory --allow-guests ``` -------------------------------- ### Installing CSharpier CLI Tool (Shell) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net/README.md This shell command installs CSharpier as a .NET local tool. It should be executed at the root of the project to make the `csharpier` command available for code formatting. ```sh dotnet tool install csharpier ``` -------------------------------- ### Starting Local SurrealDB Instance for Testing Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net.LiveQuery.Tests/README.md This command starts a local SurrealDB instance configured for testing purposes. It enables debug logging, sets root user credentials, uses an in-memory database, and allows guest connections, which is necessary for integration tests. ```sh surreal start --log debug --user root --pass root memory --allow-guests ``` -------------------------------- ### Installing SurrealDb.Net Package (Shell) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net/README.md This command installs the official SurrealDB .NET SDK package using the .NET CLI. It adds the `SurrealDb.Net` NuGet package to the current project, making the SDK's functionalities available for use. ```sh dotnet add package SurrealDb.Net ``` -------------------------------- ### Starting SurrealDB Local Instance - Shell Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Examples.Console/README.md This shell command initializes a local SurrealDB server instance. It configures debug logging, sets root user credentials, uses in-memory storage, and allows guest connections, serving as a prerequisite for the .NET application. ```Shell surreal start --log debug --user root --pass root memory --allow-guests ``` -------------------------------- ### Installing SurrealDB .NET SDK via NuGet Source: https://github.com/surrealdb/surrealdb.net/blob/main/README.md This command installs the SurrealDB .NET SDK package into your project using the .NET CLI's `dotnet add package` command, making the library available for use. ```sh dotnet add package SurrealDb.Net ``` -------------------------------- ### Starting Local SurrealDB Instance Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net.Benchmarks.Remote/README.md This command starts a local SurrealDB instance in memory mode, allowing guest access. It sets the root user and password for the database, which is required for the benchmarks to connect and operate. ```Shell surreal start --user root --pass root memory --allow-guests ``` -------------------------------- ### Installing CSharpier .NET Tool (Shell) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net.Tests/README.md Installs the CSharpier code formatter as a .NET global tool. This command should be executed from the root directory of the SurrealDB.NET project to ensure it's available for formatting. ```Shell # Run this command at the root of the project dotnet tool install csharpier ``` -------------------------------- ### Example appsettings.json for SurrealDB Connection String Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.InMemory/README.md This JSON snippet provides an example `appsettings.json` configuration, defining a `SurrealDB` connection string. This string specifies the in-memory endpoint, namespace, and database for SurrealDB, allowing for external configuration. ```json { "AllowedHosts": "*", "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "ConnectionStrings": { "SurrealDB": "Endpoint=mem://;Namespace=test;Database=test" } } ``` -------------------------------- ### Running .NET Console Application - Shell Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Examples.Console/README.md This command executes the .NET console application from the command line. It assumes the SurrealDB server is already running and accessible at `127.0.0.1:8000`, demonstrating how to launch the example application. ```Shell dotnet run ``` -------------------------------- ### Installing CSharpier via .NET Tool Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.SurrealKv/README.md This shell command demonstrates how to install CSharpier, an opinionated code formatter, as a .NET local tool. This command should be executed at the root of the project to make the `csharpier` command available for formatting C# code. ```sh dotnet tool install csharpier ``` -------------------------------- ### Starting Local SurrealDB Instance (Shell) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net.Tests/README.md Starts a local SurrealDB instance in memory mode with debug logging, root user credentials, and guest access allowed. This instance is a prerequisite for running integration tests, providing the necessary database environment. ```Shell surreal start --log debug --user root --pass root memory --allow-guests ``` -------------------------------- ### Installing CSharpier .NET Tool (sh) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.InMemory/README.md This shell command installs CSharpier as a .NET local tool. CSharpier is an opinionated code formatter used in the project to maintain consistent code style. This command should be executed at the root of the project directory. ```sh dotnet tool install csharpier ``` -------------------------------- ### Installing SurrealDB .NET SDK Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.InMemory/README.md This command adds the `SurrealDb.Embedded.InMemory` NuGet package to your .NET project, enabling the use of the in-memory SurrealDB client. ```sh dotnet add package SurrealDb.Embedded.InMemory ``` -------------------------------- ### Example appsettings.json for SurrealDB Connection String (JSON) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.RocksDb/README.md This JSON snippet provides an example `appsettings.json` configuration, defining a connection string named 'SurrealDB' within the 'ConnectionStrings' section. This string specifies the endpoint for a RocksDB instance, along with optional namespace and database parameters. ```json { "AllowedHosts": "*", "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "ConnectionStrings": { "SurrealDB": "Endpoint=rocksdb://data.db;Namespace=test;Database=test" } } ``` -------------------------------- ### Installing CSharpier Code Formatter via .NET Tool Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.RocksDb/README.md This shell command installs CSharpier, an opinionated code formatter, as a local .NET tool. It should be executed from the root directory of the project to make the `csharpier` command available for use within the project's context. ```sh dotnet tool install csharpier ``` -------------------------------- ### Installing SurrealDB .NET SDK Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.SurrealKv/README.md This snippet demonstrates how to add the SurrealDB embedded SurrealKV package to a .NET project using the dotnet CLI, which is the first step to integrate SurrealDB into your application. ```sh dotnet add package SurrealDb.Embedded.SurrealKv ``` -------------------------------- ### Configuring SurrealDB Client with Connection String in C# Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.SurrealKv/README.md This C# snippet demonstrates how to configure the SurrealDB client using a connection string retrieved from configuration, simplifying the setup process by automatically parsing endpoint, namespace, and database details. This approach leverages standard .NET configuration patterns. ```csharp services .AddSurreal(configuration.GetConnectionString("SurrealDB")) .AddSurrealKvProvider(); ``` -------------------------------- ### Consuming ISurrealDbClient via Dependency Injection Source: https://github.com/surrealdb/surrealdb.net/blob/main/README.md This example illustrates how to consume the `ISurrealDbClient` interface within a class using constructor injection. Once registered via `services.AddSurreal()`, the client instance is automatically provided, enabling interaction with SurrealDB. ```csharp public class MyClass { private readonly ISurrealDbClient _client; public MyClass(ISurrealDbClient client) { _client = client; } // ... } ``` -------------------------------- ### Example Branch Naming Convention for GitHub Source: https://github.com/surrealdb/surrealdb.net/blob/main/CONTRIBUTING.md This example demonstrates the recommended branch naming convention for contributions, combining a type (e.g., bugfix), an issue ID, and a descriptive summary of the changes. This structure helps provide immediate context for the task resolved in the branch. ```Shell bugfix-548-ensure-queries-execute-sequentially ``` -------------------------------- ### Configuring SurrealDB Client with Connection String in C# Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.InMemory/README.md This C# snippet demonstrates how to configure the SurrealDB client using a connection string retrieved from configuration. It simplifies setup by automatically parsing endpoint, namespace, and database details from the string. ```csharp services .AddSurreal(configuration.GetConnectionString("SurrealDB")) .AddInMemoryProvider(); ``` -------------------------------- ### Example SurrealDB Query Output - JSON Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Examples.Console/README.md This JSON block illustrates typical output from queries against a SurrealDB instance, showcasing individual records and arrays of records. It provides examples of the data structures returned by the database, including nested objects and null values. ```JSON { "Title": "Founder \u0026 CEO", "Name": { "FirstName": "Tobie", "LastName": "Morgan Hitchcock" }, "Marketing": true, "id": "person:zdnk39wm0vk3olv75az7" } { "Title": null, "Name": null, "Marketing": true, "id": "person:jaime" } [ { "Title": null, "Name": null, "Marketing": true, "id": "person:jaime" }, { "Title": "Founder \u0026 CEO", "Name": { "FirstName": "Tobie", "LastName": "Morgan Hitchcock" }, "Marketing": true, "id": "person:zdnk39wm0vk3olv75az7" } ] [ { "Marketing": true, "Count": 2 } ] ``` -------------------------------- ### Injecting ISurrealDbClient into a Class (C#) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.RocksDb/README.md This C# example demonstrates how to consume the registered `ISurrealDbClient` interface within a class. By injecting it through the constructor, the class gains access to the SurrealDB client instance, allowing it to perform database operations. ```csharp public class MyClass { private readonly ISurrealDbClient _client; public MyClass(ISurrealDbClient client) { _client = client; } // ... } ``` -------------------------------- ### SurrealDB Connection String Configuration (JSON) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net/README.md This JSON snippet shows an example `appsettings.json` configuration for a SurrealDB connection string. It defines the server endpoint, namespace, database, username, and password, allowing for external configuration of the SurrealDB client. ```json { "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" } } ``` -------------------------------- ### Installing SurrealDB.Embedded.RocksDb Package (Shell) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.RocksDb/README.md This command adds the SurrealDb.Embedded.RocksDb NuGet package to your .NET project, enabling the use of SurrealDB with RocksDB as the embedded database. This is the first step to integrate the SurrealDB .NET SDK. ```sh dotnet add package SurrealDb.Embedded.RocksDb ``` -------------------------------- ### Configuring SurrealDB Client with Connection String via DI (C#) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.RocksDb/README.md This C# snippet demonstrates how to register the SurrealDB client using a connection string retrieved from the application's configuration (e.g., `appsettings.json`) with dependency injection. This method simplifies client setup by centralizing connection details. ```csharp services .AddSurreal(configuration.GetConnectionString("SurrealDB")) .AddRocksDbProvider(); ``` -------------------------------- ### Injecting ISurrealDbClient into a Class (C#) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net/README.md This C# example demonstrates how to inject the `ISurrealDbClient` interface into a class constructor when using dependency injection. The injected client can then be used within the class to interact with SurrealDB. ```csharp public class MyClass { private readonly ISurrealDbClient _client; public MyClass(ISurrealDbClient client) { _client = client; } // ... } ``` -------------------------------- ### Registering Multiple SurrealDB Client Instances (C#) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net/README.md This C# example illustrates how to register multiple distinct SurrealDB client instances for dependency injection by using custom interfaces. Each client is configured with a different connection string, allowing applications to target various SurrealDB instances or databases simultaneously. ```csharp interface IBackupSurrealDbClient : ISurrealDbClient { } interface IMonitoringSurrealDbClient : ISurrealDbClient { } services.AddSurreal(configuration.GetConnectionString("SurrealDB.Main")); services.AddSurreal(configuration.GetConnectionString("SurrealDB.Backup")); services.AddSurreal(configuration.GetConnectionString("SurrealDB.Monitoring")); ``` -------------------------------- ### Configuring Default SurrealDB Client with Dependency Injection in C# Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.SurrealKv/README.md This C# snippet illustrates how to register a default SurrealDB client instance using dependency injection, specifying the SurrealKV endpoint. This setup allows the ISurrealDbClient interface or SurrealDbClient class to be injected throughout the application, promoting modularity. ```csharp services. .AddSurreal("Endpoint=surrealkv://data.db") .AddSurrealKvProvider(); ``` -------------------------------- ### Retrieving SurrealDB Version Information Source: https://github.com/surrealdb/surrealdb.net/blob/main/CONTRIBUTING.md This command-line utility provides the version identifier of the installed SurrealDB instance. It is particularly important for security vulnerability reports, as it helps the team understand the specific environment where an issue was found. ```Bash surreal version ``` -------------------------------- ### Filtering Live Query Create Events - C# Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Reactive/README.md This C# example shows how to filter live query responses to specifically capture only 'CREATE' events for 'PostRecord' types, allowing real-time processing of newly created records. ```C# client .ObserveTable("post") .OfType>() .Select(r => r.Result) .Subscribe(record => { // you can filter out the LQ type and get every created records in realtime }); ``` -------------------------------- ### SurrealDB Connection String in appsettings.json Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.SurrealKv/README.md This JSON snippet provides an example of how to define a SurrealDB connection string within an appsettings.json file, including endpoint, namespace, and database details. This allows for external configuration of database connections, enhancing flexibility. ```json { "AllowedHosts": "*", "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "ConnectionStrings": { "SurrealDB": "Endpoint=surrealkv://data.db;Namespace=test;Database=test" } } ``` -------------------------------- ### Displaying Icons with Open Iconic and Foundation - HTML Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Examples.Blazor.Server/wwwroot/css/open-iconic/README.md This example shows the HTML markup for displaying an Open Iconic font icon when the Foundation-compatible stylesheet is linked. Icons are rendered using `` tags with the `fi-icon-name` class, along with `title` and `aria-hidden` attributes for accessibility. ```HTML ``` -------------------------------- ### Embedding Icons with SVG Sprite - HTML Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Examples.Blazor.Server/wwwroot/css/open-iconic/README.md This example illustrates how to use Open Iconic's SVG sprite for displaying icons, which allows loading multiple icons with a single request. It suggests adding a general class to the `` tag and a unique class to the `` tag for easier styling. ```HTML ``` -------------------------------- ### Implementing REST API with SurrealDB .NET Client in C# Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.RocksDb/README.md This C# snippet demonstrates how to create a RESTful API controller using ASP.NET Core to interact with SurrealDB via the `ISurrealDbClient`. It covers various HTTP methods (GET, POST, PUT, PATCH, DELETE) mapped to SurrealDB operations like `Select`, `Create`, `Upsert`, `Patch`, and `Delete`, showcasing how to handle data retrieval, creation, updates, and deletions for a 'WeatherForecast' entity. ```csharp [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> GetAll(CancellationToken cancellationToken) { return _surrealDbClient.Select(Table, cancellationToken); } [HttpGet("{id}")] public async Task Get(string id, CancellationToken cancellationToken) { var weatherForecast = await _surrealDbClient.Select((Table, id), cancellationToken); if (weatherForecast is null) return NotFound(); return Ok(weatherForecast); } [HttpPost] public Task 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 Update(WeatherForecast data, CancellationToken cancellationToken) { return _surrealDbClient.Upsert(data, cancellationToken); } [HttpPatch] public Task> PatchAll( JsonPatchDocument patches, CancellationToken cancellationToken ) { return _surrealDbClient.PatchAll(Table, patches, cancellationToken); } [HttpPatch("{id}")] public Task Patch( string id, JsonPatchDocument 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 Delete(string id, CancellationToken cancellationToken) { bool success = await _surrealDbClient.Delete((Table, id), cancellationToken); if (!success) return NotFound(); return Ok(); } } ``` -------------------------------- ### Implementing SurrealDB CRUD Operations in ASP.NET Core (C#) Source: https://github.com/surrealdb/surrealdb.net/blob/main/README.md This `WeatherForecastController` example illustrates how to perform various CRUD operations against a SurrealDB instance using the `ISurrealDbClient` interface within an ASP.NET Core Web API. It covers `Select`, `Create`, `Upsert`, `Patch`, and `Delete` methods for managing `WeatherForecast` entities, demonstrating both single-record and collection operations. ```C# [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> GetAll(CancellationToken cancellationToken) { return _surrealDbClient.Select(Table, cancellationToken); } [HttpGet("{id}")] public async Task Get(string id, CancellationToken cancellationToken) { var weatherForecast = await _surrealDbClient.Select((Table, id), cancellationToken); if (weatherForecast is null) return NotFound(); return Ok(weatherForecast); } [HttpPost] public Task 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 Update(WeatherForecast data, CancellationToken cancellationToken) { return _surrealDbClient.Upsert(data, cancellationToken); } [HttpPatch] public Task> PatchAll( JsonPatchDocument patches, CancellationToken cancellationToken ) { return _surrealDbClient.Patch(Table, patches, cancellationToken); } [HttpPatch("{id}")] public Task Patch( string id, JsonPatchDocument 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 Delete(string id, CancellationToken cancellationToken) { bool success = await _surrealDbClient.Delete((Table, id), cancellationToken); if (!success) return NotFound(); return Ok(); } } ``` -------------------------------- ### Displaying Icons with Open Iconic and Bootstrap - HTML Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Examples.Blazor.Server/wwwroot/css/open-iconic/README.md This example provides the HTML markup for displaying an Open Iconic font icon when the Bootstrap-compatible stylesheet is linked. Icons are rendered using `` tags with `oi` and `oi-icon-name` classes, along with `title` and `aria-hidden` attributes for accessibility. ```HTML ``` -------------------------------- ### Implementing CRUD Operations with SurrealDB .NET Client in ASP.NET Core Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.SurrealKv/README.md This C# code defines an ASP.NET Core API controller (`WeatherForecastController`) that demonstrates various CRUD operations (Select, Create, Upsert, Patch, Delete) using the `ISurrealDbClient` for interacting with a SurrealDB database. It handles HTTP GET, POST, PUT, PATCH, and DELETE requests, mapping them to corresponding SurrealDB client methods and managing responses like `NotFound`. ```C# [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> GetAll(CancellationToken cancellationToken) { return _surrealDbClient.Select(Table, cancellationToken); } [HttpGet("{id}")] public async Task Get(string id, CancellationToken cancellationToken) { var weatherForecast = await _surrealDbClient.Select((Table, id), cancellationToken); if (weatherForecast is null) return NotFound(); return Ok(weatherForecast); } [HttpPost] public Task 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 Update(WeatherForecast data, CancellationToken cancellationToken) { return _surrealDbClient.Upsert(data, cancellationToken); } [HttpPatch] public Task> PatchAll( JsonPatchDocument patches, CancellationToken cancellationToken ) { return _surrealDbClient.PatchAll(Table, patches, cancellationToken); } [HttpPatch("{id}")] public Task Patch( string id, JsonPatchDocument 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 Delete(string id, CancellationToken cancellationToken) { bool success = await _surrealDbClient.Delete((Table, id), cancellationToken); if (!success) return NotFound(); return Ok(); } } ``` -------------------------------- ### Displaying Icons with Open Iconic Standalone - HTML Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Examples.Blazor.Server/wwwroot/css/open-iconic/README.md This example provides the HTML markup for displaying an Open Iconic font icon when using the default stylesheet. Icons are rendered using `` tags with the `oi` class and a `data-glyph` attribute to specify the icon, along with `title` and `aria-hidden` attributes for accessibility. ```HTML ``` -------------------------------- ### Implementing SurrealDB Client in ASP.NET Core Controller (C#) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.InMemory/README.md This C# code snippet demonstrates how to integrate and use the ISurrealDbClient within an ASP.NET Core ApiController. It showcases various HTTP methods (GET, POST, PUT, PATCH, DELETE) for performing common CRUD operations (Select, Create, Upsert, Patch, Delete) against a 'weatherForecast' table in SurrealDB. The controller handles requests for single records and collections, including error handling for NotFound scenarios. ```csharp [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> GetAll(CancellationToken cancellationToken) { return _surrealDbClient.Select(Table, cancellationToken); } [HttpGet("{id}")] public async Task Get(string id, CancellationToken cancellationToken) { var weatherForecast = await _surrealDbClient.Select((Table, id), cancellationToken); if (weatherForecast is null) return NotFound(); return Ok(weatherForecast); } [HttpPost] public Task 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 Update(WeatherForecast data, CancellationToken cancellationToken) { return _surrealDbClient.Upsert(data, cancellationToken); } [HttpPatch] public Task> PatchAll( JsonPatchDocument patches, CancellationToken cancellationToken ) { return _surrealDbClient.PatchAll(Table, patches, cancellationToken); } [HttpPatch("{id}")] public Task Patch( string id, JsonPatchDocument 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 Delete(string id, CancellationToken cancellationToken) { bool success = await _surrealDbClient.Delete((Table, id), cancellationToken); if (!success) return NotFound(); return Ok(); } } ``` -------------------------------- ### Running .NET Minimal API Application (Shell) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Examples.MinimalApis/README.md This command compiles and runs the .NET Minimal API application. It assumes the SurrealDB server is already running and will make the Swagger UI accessible at `https://localhost:7102/swagger`. ```sh dotnet run ``` -------------------------------- ### Constructing SurrealDB Clients in C# Source: https://github.com/surrealdb/surrealdb.net/blob/main/README.md This snippet demonstrates how to initialize `SurrealDbClient` instances using different connection protocols (HTTP, HTTPS, WebSocket, secure WebSocket). Each client is configured with the SurrealDB endpoint, allowing subsequent operations like authentication and database selection. ```csharp 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 ``` -------------------------------- ### Running Blazor Server Application (.NET) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Examples.Blazor.Server/README.md This command executes the .NET Blazor Server application from the command line. It assumes that the SurrealDB server is already operational and accessible at '127.0.0.1:8000' for the application to connect and function correctly. ```Shell dotnet run ``` -------------------------------- ### Running ASP.NET Application (Shell) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Examples.WeatherApi/README.md This command compiles and runs the ASP.NET application from the command line. It assumes the SurrealDB server is already running and makes the Swagger UI accessible for API testing. ```sh dotnet run ``` -------------------------------- ### Constructing SurrealDB Client Instances (C#) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net/README.md This C# code demonstrates how to create new `SurrealDbClient` instances for different connection protocols: HTTP, HTTPS, WebSocket, and secure WebSocket. Each client is initialized with a specific endpoint, allowing direct interaction with a SurrealDB instance. ```csharp 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 ``` -------------------------------- ### Configuring SurrealDB Client for Dependency Injection with Options Source: https://github.com/surrealdb/surrealdb.net/blob/main/README.md This code shows how to configure the SurrealDB client for dependency injection using `SurrealDbOptions`. It sets the endpoint, namespace, database, username, and password, then registers the client with the service collection using `services.AddSurreal()`. ```csharp var options = SurrealDbOptions .Create() .WithEndpoint("http://127.0.0.1:8000") .WithNamespace("test") .WithDatabase("test") .WithUsername("root") .WithPassword("root") .Build(); services.AddSurreal(options); ``` -------------------------------- ### Cloning a Git Repository for Contribution Source: https://github.com/surrealdb/surrealdb.net/blob/main/CONTRIBUTING.md This command initiates the process of downloading the SurrealDB project repository from GitHub to your local machine. It's the essential first step after forking the project to begin local development. ```Bash git clone ``` -------------------------------- ### Configuring Default SurrealDB Client for Dependency Injection (C#) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net/README.md This C# snippet shows how to configure a default `SurrealDbClient` instance for dependency injection using `SurrealDbOptions`. It sets the endpoint, namespace, database, username, and password, then registers the client with the service collection using `services.AddSurreal()`. ```csharp var options = SurrealDbOptions .Create() .WithEndpoint("http://127.0.0.1:8000") .WithNamespace("test") .WithDatabase("test") .WithUsername("root") .WithPassword("root") .Build(); services.AddSurreal(options); ``` -------------------------------- ### Building Embedded Rust Crate for SurrealDB.NET (Shell) Source: https://github.com/surrealdb/surrealdb.net/blob/main/README.md This shell command sequence details how to build the local Rust crate required by SurrealDB.NET's embedded providers. Users must navigate to the `./rust-embedded` directory and then execute `cargo build` to compile the Rust libraries, which are subsequently copied for .NET project builds. ```sh cd ./rust-embedded cargo build ``` -------------------------------- ### Running CSharpier Code Formatter Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.MinimalApis.Extensions/README.md This command executes the CSharpier code formatter across the entire project. It formats all files in the current directory and its subdirectories according to CSharpier's rules, ensuring consistent code style. ```sh dotnet csharpier . ``` -------------------------------- ### Running Remote Benchmarks for .NET Project Source: https://github.com/surrealdb/surrealdb.net/blob/main/README.md Executes the remote performance benchmarks for the SurrealDb.Net project in release configuration. The filter '*' ensures all benchmarks are run. ```sh dotnet run -c Release --project SurrealDb.Net.Benchmarks.Remote --filter '*' ``` -------------------------------- ### Running Embedded Benchmarks on Unix Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net.Benchmarks.Embedded/README.md These commands are used on Unix-like systems to prepare the environment, execute the SurrealDb.Net embedded benchmarks in Release configuration, and subsequently clean up the environment. ```sh ./prepare_embedded_benchmarks.sh -s dotnet run -c Release --project SurrealDb.Net.Benchmarks.Embedded --filter '*' ./prepare_embedded_benchmarks.sh -e ``` -------------------------------- ### Constructing SurrealDB RocksDB Client and Creating Record (C#) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.RocksDb/README.md This C# snippet demonstrates how to initialize an embedded SurrealDB client backed by RocksDB by specifying a data file path. It then shows how to define a 'person' object and use the client's `Create` method to persist the data, printing the created record to the console. ```csharp using var db = new SurrealDbRocksDbClient("data.db"); 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)); ``` -------------------------------- ### Configuring Multiple SurrealDB Instances with Keyed Services (C#) Source: https://github.com/surrealdb/surrealdb.net/blob/main/README.md This snippet demonstrates how to register multiple SurrealDB client instances using dependency injection in a .NET application. It shows the use of `services.AddSurreal` for a default client and `services.AddKeyedSurreal` to register named instances ('backup', 'monitoring') for targeting different SurrealDB connections or databases. ```C# services.AddSurreal(configuration.GetConnectionString("SurrealDB.Main")); services.AddKeyedSurreal("backup", configuration.GetConnectionString("SurrealDB.Backup")); services.AddKeyedSurreal("monitoring", configuration.GetConnectionString("SurrealDB.Monitoring")); ``` -------------------------------- ### Running .NET Integration Tests Source: https://github.com/surrealdb/surrealdb.net/blob/main/README.md Executes the primary suite of integration tests for the SurrealDb.Net project. The `dotnet watch test` command allows for continuous testing during development. ```sh dotnet watch test --project SurrealDb.Net.Tests ``` -------------------------------- ### Constructing a SurrealDBKvClient in C# Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.SurrealKv/README.md This C# snippet shows how to initialize a new SurrealDbKvClient instance, create a 'person' record, and then persist it to the database. It demonstrates basic CRUD operations with an embedded SurrealDB instance, using 'data.db' as the file storage. ```csharp using var db = new SurrealDbKvClient("data.db"); 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)); ``` -------------------------------- ### Running Embedded Benchmarks (Linux/macOS) Source: https://github.com/surrealdb/surrealdb.net/blob/main/README.md A sequence of commands to prepare, run, and clean up embedded benchmarks on Linux or macOS. This involves setting up the embedded environment, executing the benchmarks, and then cleaning up. ```sh ./prepare_embedded_benchmarks.sh -s dotnet run -c Release --project SurrealDb.Net.Benchmarks.Embedded --filter '*' ./prepare_embedded_benchmarks.sh -e ``` -------------------------------- ### Running Embedded Benchmarks on Windows Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net.Benchmarks.Embedded/README.md These commands are designed for Windows systems to prepare the environment, run the SurrealDb.Net embedded benchmarks in Release configuration using PowerShell, and then perform necessary cleanup. ```powershell ./prepare_embedded_benchmarks.ps1 -s dotnet run -c Release --project SurrealDb.Net.Benchmarks.Embedded --filter '*' ./prepare_embedded_benchmarks.ps1 -e ``` -------------------------------- ### Running .NET Live Query Tests Source: https://github.com/surrealdb/surrealdb.net/blob/main/README.md Executes the specific test project for SurrealDb.Net Live Queries. Due to the asynchronous nature of Live Queries, this project disables test parallelization and may take longer to complete. ```sh dotnet watch test --project SurrealDb.Net.LiveQuery.Tests ``` -------------------------------- ### Running CSharpier Code Formatter - Shell Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Reactive/README.md This command executes the CSharpier tool to format all C# code files within the current directory and its subdirectories, applying the configured formatting rules. ```Shell dotnet csharpier . ``` -------------------------------- ### Configuring SurrealDB Client with Connection String via DI Source: https://github.com/surrealdb/surrealdb.net/blob/main/README.md This code demonstrates how to register the SurrealDB client for dependency injection using a connection string retrieved from configuration. The `AddSurreal` method automatically parses the connection string to configure the client's endpoint, namespace, database, and authentication details. ```csharp services.AddSurreal(configuration.GetConnectionString("SurrealDB")); ``` -------------------------------- ### Registering SurrealDB Client with Connection String (C#) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net/README.md This C# code demonstrates how to register the SurrealDB client for dependency injection using a connection string retrieved from configuration. The connection string automatically configures the client's endpoint, namespace, database, username, and password. ```csharp services.AddSurreal(configuration.GetConnectionString("SurrealDB")); ``` -------------------------------- ### Running CSharpier for Code Formatting Source: https://github.com/surrealdb/surrealdb.net/blob/main/README.md Executes the CSharpier formatter on all applicable files within the current directory and its subdirectories. This ensures adherence to the project's defined code style. ```sh dotnet csharpier . ``` -------------------------------- ### Inserting Sample Data into 'post' Table in SurrealDB Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net.Tests/Snapshots/ExportTests.ShouldExportFullDatabaseWithDefaultOptions.verified.txt This command inserts a single record into the 'post' table. The record includes 'content', 'created_at' (using a datetime literal), a specific 'id' for the post, 'status', and 'title'. This demonstrates how to add new data entries into a defined table. ```SurrealQL INSERT [ { content: 'This is a new article created using the .NET SDK', created_at: d'DateTime_1', id: post:⟨dotnet-123456⟩, status: 'DRAFT', title: 'A new article' } ]; ``` -------------------------------- ### Configuring Multiple SurrealDB Client Instances in C# Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.SurrealKv/README.md This C# snippet illustrates how to register multiple distinct SurrealDB client instances with dependency injection, each bound to a specific interface and configured with its own connection string. This enables targeting different SurrealDB instances or databases within a single application, providing isolation and flexibility. ```csharp interface IBackupSurrealDbClient : ISurrealDbClient { } interface IMonitoringSurrealDbClient : ISurrealDbClient { } services .AddSurreal(configuration.GetConnectionString("SurrealDB.Main")) .AddSurrealKvProvider(); services.AddSurreal(configuration.GetConnectionString("SurrealDB.Backup")); services.AddSurreal(configuration.GetConnectionString("SurrealDB.Monitoring")); ``` -------------------------------- ### Registering Multiple SurrealDB Client Instances with DI (C#) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.RocksDb/README.md This C# snippet illustrates how to register multiple distinct SurrealDB client instances using dependency injection, each bound to a specific interface. This pattern allows different parts of an application to target separate SurrealDB databases or configurations concurrently. ```csharp interface IBackupSurrealDbClient : ISurrealDbClient { } interface IMonitoringSurrealDbClient : ISurrealDbClient { } services .AddSurreal(configuration.GetConnectionString("SurrealDB.Main")) .AddRocksDbProvider(); services.AddSurreal(configuration.GetConnectionString("SurrealDB.Backup")); services.AddSurreal(configuration.GetConnectionString("SurrealDB.Monitoring")); ``` -------------------------------- ### Configuring Default SurrealDB RocksDB Client with Dependency Injection (C#) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.RocksDb/README.md This C# snippet illustrates how to register the default SurrealDB client with the RocksDB provider using .NET's dependency injection. It configures the client to connect to a RocksDB instance located at 'data.db', making `ISurrealDbClient` or `SurrealDbClient` available for injection. ```csharp services. .AddSurreal("Endpoint=rocksdb://data.db") .AddRocksDbProvider(); ``` -------------------------------- ### Running CSharpier for Code Formatting Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net.LiveQuery.Tests/README.md This command executes CSharpier to format all code files within the current directory and its subdirectories. It applies the opinionated formatting rules defined by CSharpier. ```sh dotnet csharpier . ``` -------------------------------- ### Constructing and Using SurrealDB Memory Client in C# Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.InMemory/README.md This C# snippet demonstrates how to instantiate an in-memory SurrealDB client (`SurrealDbMemoryClient`) and perform a `Create` operation. It shows defining a `Person` object and writing the created record to the console, illustrating basic data interaction. ```csharp 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)); ``` -------------------------------- ### Running CSharpier for Code Formatting (sh) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Embedded.InMemory/README.md This shell command executes CSharpier to format all code files within the current directory and its subdirectories. It applies the project's defined formatting rules to ensure code consistency. This command should be run from the project's root. ```sh dotnet csharpier . ``` -------------------------------- ### Running CSharpier for Formatting (Shell) Source: https://github.com/surrealdb/surrealdb.net/blob/main/SurrealDb.Net.Tests/README.md Executes the CSharpier formatter on all files in the current directory and its subdirectories. This command formats the entire project according to CSharpier's opinionated rules, ensuring consistent code style. ```Shell dotnet csharpier . ```