Skip to main content

Getting Started

Prerequisites

The Tigris client depends on Golang generics which requires Go 1.18 or newer.

Installation

Install Tigris client as a dependency of you Go modules enabled project.

go get -u github.com/tigrisdata/tigris-client-go@latest

Create Connection

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

cfg := &config.Database{
Driver: config.Driver{
URL: "api.preview.tigrisdata.cloud"
ClientID: "paste client_id here"
ClientSecret: "paste client_secret here"
}
}

client, err := tigris.NewClient(ctx, cfg)

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

Set up the data model

Models are regular Go structs composed of basic Go types or custom types.

type Reviews struct {
Author string
Ratings float64
}

type Catalog struct {
Id int `tigris:"primary_key,autoGenerate"`
Name string
Price float64
Brand string
Labels string
Popularity int
Reviews *Reviews
}

This declaration will create a collection named catalogs.

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

Create Database and Collections

The OpenDatabase creates the database and collections if they don't exist, otherwise updates the schema of the collections if they already exist.

db, err := client.OpenDatabase(ctx, "catalogdb", &Catalog{})