Skip to main content

Getting Started

Prerequisites

The Tigris client is compatible with Node version 12 onwards.

Installation

npm install @tigrisdata/core

Create Connection

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

const tigris = new Tigris({
serverUrl: "api.preview.tigrisdata.cloud",
clientId: "paste client_id here",
clientSecret: "paste client_secret here",
});

The ClientID and ClientSecret can be retrieved by creating an application in the CLI or UI.

Set up the data model

Tigris client uses interface for data container and developers define the schema of their data container using TigrisSchema

DataContainer
interface Catalog extends TigrisCollectionType {
id?: string;
name: string;
price: number;
brand: string;
labels: string;
popularity: number;
}
SchemaDefinition
const catalogSchema: TigrisSchema<Catalog> = {
id: {
type: TigrisDataTypes.INT64,
primary_key: {
order: 1,
autoGenerate: true,
},
},
name: {
type: TigrisDataTypes.STRING,
},
price: {
type: TigrisDataTypes.NUMBER,
},
brand: {
type: TigrisDataTypes.STRING,
},
labels: {
type: TigrisDataTypes.STRING,
},
popularity: {
type: TigrisDataTypes.INT32,
},
};

For detailed documentation on schema representation refer to the data modeling section.

Create Database and Collection

1. Create database (if not exists)

const db = await tigris.createDatabaseIfNotExists("catalogdb");

2. Create collection

const catalog = await db.createOrUpdateCollection<Catalog>(
"catalog",
catalogSchema
);