Skip to main content

TypeScript Reference

npm

Tigris provides an easy-to-use and intuitive interface for TypeScript. Setting up the database is instantaneous, as well - no need for tedious configuration. You define the data model as part of the application code, which then drives the database infrastructure without you having to configure and provision database resources.

1. Install package

npm install @tigrisdata/core

Getting started →

2. Connect and define data models

const tigris = new Tigris({
serverUrl: "api.preview.tigrisdata.cloud",
clientId: 'xxx',
clientSecret: 'xxx'
});

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

interface Catalog extends TigrisCollectionType {
id?: string;
name: string;
price: number;
brand: string;
labels: string;
popularity: number;
}

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,
},
};

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

Declaring models →

3. Persist data

const insertedProduct = await catalog.insertOne({
name: "fiona handbag",
price: 99.9,
brand: "michael kors",
labels: "purses",
popularity: 8,
});

Insert documents →

4. Query data

catalog.findOne({ brand: "adidas" })
.then(product: Catalog => {
console.log(product.name); // 'sneakers shoes'
console.log(product.price); // 40
});

Query documents →

5. Search data

const request: SearchRequest<Catalog> = {
q: "running",
};

catalog.search(request, {
onEnd() {
// when search completes
},
onNext(result: SearchResult<Catalog>) {
// when a search result is fetched
},
onError(error: Error) {
// in case of an error
},
});

Search documents →