ImmuDB4Net 1.0.5-rc2

This is a prerelease version of ImmuDB4Net.
There is a newer version of this package available.
See the version list below for details.
dotnet add package ImmuDB4Net --version 1.0.5-rc2                
NuGet\Install-Package ImmuDB4Net -Version 1.0.5-rc2                
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="ImmuDB4Net" Version="1.0.5-rc2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ImmuDB4Net --version 1.0.5-rc2                
#r "nuget: ImmuDB4Net, 1.0.5-rc2"                
#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.
// Install ImmuDB4Net as a Cake Addin
#addin nuget:?package=ImmuDB4Net&version=1.0.5-rc2&prerelease

// Install ImmuDB4Net as a Cake Tool
#tool nuget:?package=ImmuDB4Net&version=1.0.5-rc2&prerelease                

ImmuDB4Net - The Official immudb Client for .NET License

Contents

1. Introduction

ImmuDB4Net implements a gRPC immudb client, based on [immudb's official protobuf definition]. It exposes a minimal and simple to use API for applications, while the cryptographic verifications and state update protocol implementation are fully implemented internally by this client.

The latest validated immudb state may be kept in the local file system using default FileImmuStateHolder. Please read immudb Research Paper for details of how immutability is ensured by immudb.

immudb's official protobuf definition

2. Prerequisites

ImmuDB4Net assumes you have access to a running immudb server. Running immudb on your system is very simple, please refer to this immudb QuickStart page.

3. Installation

Include ImmuDB4Net as a dependency in your project via Nuget package. ImmuDB4Net is currently hosted on NuGet.Org

4. Build locally from sources

Use dotnet build to build locally the ImmuDB client assembly.

5. Supported Versions

ImmuDB4Net supports the latest immudb server release, that is 1.3.2 at the time of updating this document.

6. Quickstart

Hello Immutable World! example can be found in immudb-client-examples repo:

7. Step-by-step Guide

7.1. Creating a Client

The following code snippets show how to create a client.

Using default configuration:

    ImmuClient immuClient = ImmuClient.NewBuilder().Build();

    // or

    Immuclient immuClient = new ImmuClient();
    Immuclient immuClient = new ImmuClient("localhost", 3322);
    Immuclient immuClient = new ImmuClient("localhost", 3322, "defaultdb");


Setting immudb url and port:

    ImmuClient immuClient = ImmuClient.NewBuilder()
                                .WithServerUrl("localhost")
                                .WithServerPort(3322)
                                .Build();

    ImmuClient immuClient = ImmuClient.NewBuilder()
                                .WithServerUrl("localhost")
                                .WithServerPort(3322)
                                .Build();

Customizing the State Holder:

    FileImmuStateHolder stateHolder = FileImmuStateHolder.NewBuilder()
                                        .WithStatesFolder("./my_immuapp_states")
                                        .Build();

    ImmuClient immuClient = ImmuClient.NewBuilder()
                                      .WithStateHolder(stateHolder)
                                      .Build();

7.2. User Sessions

Use Open and Close methods to initiate and terminate user sessions:

    await immuClient.Open("usr1", "pwd1", "defaultdb");

    // Interact with immudb using logged-in user.
    //...

    await immuClient.Close();

    // or one liner open the session right 
    client = await ImmuClient.NewBuilder().Open();

    //then close it
    await immuClient.Close();

7.3. Creating a Database

Creating a new database is quite simple:

    await immuClient.CreateDatabase("db1");

7.4. Setting the Active Database

Specify the active database with:

    await immuClient.UseDatabase("db1");

7.5. Standard Read and Write

immudb provides standard read and write operations that behave as in a standard key-value store i.e. no cryptographic verification is involved. Such operations may be used when validations can be postponed.

    await client.Set("k123", "v123");
    string v = await client.Get("k123").ToString();
or
    await client.Set("k123", new byte[]{1, 2, 3});
    byte[] v = await client.Get("k123").Value;

7.6. Verified or Safe Read and Write

immudb provides built-in cryptographic verification for any entry. The client implements the mathematical validations while the application uses as a standard read or write operation:

    try 
    {
        await Client.VerifiedSet("k123", new byte[]{1, 2, 3});
        byte[] v = await client.VerifiedGet("k123").Value;
or
        await client.VerifiedSet("k123", "v123");
        string v = await client.VerifiedGet("k123").ToString();

    } catch(VerificationException e) {

        // Check if it is a data tampering detected case!

    }

7.7. Multi-key Read and Write

Transactional multi-key read and write operations are supported by immudb and ImmuDB4Net.

Atomic multi-key write (all entries are persisted or none):

        List<KVPair> kvs = new List<KVPair>() 
        {
            new KVPair("sga-key1", new byte[] {1, 2}),
            new KVPair("sga-key2", new byte[] {3, 4})
        }

        try 
        {
            await immuClient.SetAll(kvs);
        } catch (CorruptedDataException e) 
        {
            // ...
        }

Atomic multi-key read (all entries are retrieved or none):

    List<string> keys = new List<string>() {key1, key2, key3};
    List<Entry> result = await immuClient.GetAll(keys);

    foreach(Entry entry in result) {
        byte[] key = entry.Key;
        byte[] value = entry.Value;
        // ...
    }

7.8. Executing SQL statements and queries

ImmuDB4Net provides SQLExec and SQLQuery commands and an example of usage is below:

        var client = new ImmuClient();
        await client.Open("immudb", "immudb", "defaultdb");

        await client.SQLExec("CREATE TABLE IF NOT EXISTS logs(id INTEGER AUTO_INCREMENT, created TIMESTAMP, entry VARCHAR, PRIMARY KEY id)");
        await client.SQLExec("CREATE INDEX IF NOT EXISTS ON logs(created)");
        var rspInsert = await client.SQLExec("INSERT INTO logs(created, entry) VALUES($1, $2)",
                SQLParameter.Create(DateTime.UtcNow),
                SQLParameter.Create("hello immutable world"));
        var queryResult = await client.SQLQuery("SELECT created, entry FROM LOGS order by created DESC");
        var sqlVal = queryResult.Rows[0]["entry"];
        
        Console.WriteLine($"The log entry is: {sqlVal.Value}");

7.9. Closing the client

Use Close, for closing the connection with immudb server . When terminating the process, use the ImmuClient.ReleaseSdkResources function :

    await client.Close();
    await ImmuClient.ReleaseSdkResources();

Note: After the shutdown, a new client needs to be created to establish a new connection.

8. Building from source

To build from source you need as prerequisites to clone a local copy of the git repo: https://github.com/codenotary/immudb4net and then to have installed on the build machine the dotnet 6.0 SDK. Then, from the terminal just run dotnet build .

In order to successfully execute the integration tests with the commanddotnet test you have to install as prerequisites docker and also to start locally an ImmuDB instance on port 3322. For example, you can run ImmuDB in docker as below:

docker run -d --name immudb -p 3322:3322 codenotary/immudb:latest

9. Contributing

We welcome contributions. Feel free to join the team!

To report bugs or get help, use GitHub's issues.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.5 3,735 10/13/2022
1.0.5-rc2 271 9/27/2022
1.0.5-rc 165 9/8/2022