Skip to main content

Getting Started

Installation

<!-- https://mvnrepository.com/artifact/com.tigrisdata/tigris-client -->
<dependency>
<groupId>com.tigrisdata</groupId>
<artifactId>tigris-client</artifactId>
<version>insert_client_version_here</version>
</dependency>

Further instructions are available here for additional build tools.

import com.tigrisdata.db.client.*;
import com.tigrisdata.db.annotation.*;
import com.tigrisdata.db.type.*;

Client

The Tigris Java client libraries offer both asynchronous and synchronous clients.

The asynchronous client provides non-blocking, asynchronous APIs for interacting with Tigris. These APIs let you use the SDK to build scalable applications that use system resources in an efficient way.

While the synchronous clients cater to a wider audience, and also make the client libraries approachable for users not familiar with asynchronous programming.

tip

We recommend using the asynchronous clients for production systems to maximize the use of system resources.

Create Connection

Tigris URL, ClientID and ClientSecret need to be set as follows, in order to connect to the hosted platform:

TigrisConfiguration configuration = TigrisConfiguration.newBuilder("api.preview.tigrisdata.cloud")
.withAuthConfig(new TigrisConfiguration.AuthConfig("paste client_id here", "paste client_secret here"))
.build();
// client
TigrisClient client = StandardTigrisClient.getInstance(tigrisConfiguration);

Create database

Creating a database is fairly easy and safe using if not exists protocol. This will throw an exception if a database with given name already exists.

TigrisDatabase db = client.createDatabaseIfNotExists("sampledb");

Retrieve database

Retrieve the database instance.

TigrisDatabase db = client.getDatabase("sampledb");

Create collection

Create a collection mapping to User.class. Read more about declaring class models for Tigris collection.

CreateOrUpdateCollectionsResponse response = db.createOrUpdateCollections(User.class);

Retrieve collection

Retrieve a collection instance.

TigrisCollection<User> collection = db.getCollection(User.class);