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 Cloud
- Development Environment
Tigris URL, ClientID and ClientSecret need to be set as follows, in order to connect to the hosted platform:
cfg := &tigris.Config{
URL: "api.preview.tigrisdata.cloud:443",
ClientID: "your-tigris-app-id",
ClientSecret: "your-tigris-app-secret",
Project: "your-tigris-project-name",
}
client, err := tigris.NewClient(ctx, cfg)
The ClientID and ClientSecret can be retrieved by creating an application in the CLI or UI.
cfg := &tigris.Config{
URL: "localhost:8081",
Project: "your-tigris-project-name",
}
client, err := tigris.NewClient(ctx, cfg)
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 Collections​
The OpenDatabase
creates the collections if they don't exist,
otherwise updates the schema of the collections if they already exist. Note:
the project is already expected to be created at this point (from Web-Console
or CLI)
db, err := client.OpenDatabase(ctx, &Catalog{})