Skip to main content
Version: 3.13

Getting Started with the Administrative API in the ScalarDB Cluster .NET Client SDK

The ScalarDB Cluster .NET Client SDK supports the Administrative API of ScalarDB Cluster. By using this API, you can manage ScalarDB Cluster from .NET applications.

note

Although we recommend using asynchronous methods as in the following examples, you can use synchronous methods instead.

Install the SDK​

Install the same major and minor version of the SDK as ScalarDB Cluster into the .NET project. You can do this by using the built-in NuGet package manager, replacing <MAJOR>.<MINOR> with the version that you're using:

dotnet add package ScalarDB.Client --version '<MAJOR>.<MINOR>.*'

Create a settings file​

Create a scalardb-options.json file and add the following, replacing <HOSTNAME_OR_IP_ADDRESS> with the FQDN or the IP address, and <PORT> with the port number (60053 by default) of your cluster:

{
"ScalarDbOptions": {
"Address": "http://<HOSTNAME_OR_IP_ADDRESS>:<PORT>",
"HopLimit": 10
}
}

For details about settings files and other ways to configure the client, see Client configuration.

Get a transaction manager​

You need to get an object for interacting with the Administrative API. To get the object, you can use TransactionFactory as follows:

// Pass the path to the settings file created in the previous step.
var factory = TransactionFactory.Create("scalardb-options.json");

using var admin = factory.GetTransactionAdmin();

Manage ScalarDB Cluster​

The following operations can be performed by using the ScalarDB Cluster .NET Client SDK.

Create a new namespace​

await admin.CreateNamespaceAsync("ns", ifNotExists: true);

Drop a namespace​

await admin.DropNamespaceAsync("ns", ifExists: true);

Check if a namespace exists​

var namespaceExists = await admin.IsNamespacePresentAsync("ns");

Create a new table​

// ...
using ScalarDB.Client.Builders.Admin;
using ScalarDB.Client.Core;

// ...

var tableMetadata =
new TableMetadataBuilder()
.AddPartitionKey("pk", DataType.Int)
.AddClusteringKey("ck", DataType.Double)
.AddSecondaryIndex("index", DataType.Float)
.AddColumn("ordinary", DataType.Text)
.Build();

await admin.CreateTableAsync("ns", "table_name", tableMetadata, ifNotExists: true);

Drop a table​

await admin.DropTableAsync("ns", "table_name", ifExists: true);

Checking if a table exists​

var tableExists = await admin.IsTablePresentAsync("ns", "table_name");

Get the names of existing tables​

var tablesList = await admin.GetTableNamesAsync("ns");

Create the Coordinator table​

await admin.CreateCoordinatorTablesAsync();

Drop the Coordinator table​

await admin.DropCoordinatorTablesAsync();

Check if the Coordinator table exist​

var exists = await admin.AreCoordinatorTablesPresentAsync();