Skip to main content

Go Reference

Go Reference

Tigris provides an easy-to-use and intuitive interface for Go. 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

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

Getting started →

2. Define data models

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
}

cfg := &tigris.Config{
URL: "localhost:8081",
Project: "your-tigris-project-name",
}

client, err := tigris.NewClient(ctx, cfg)
db, err := tigris.OpenDatabase(ctx, cfg, &User{}, &Product{}, &Order{})

Declaring models →

3. Persist data

_, err := catalogs.Insert(ctx,
&Catalog{Name: "fiona handbag", Price: 99.9, Brand: "michael kors", Labels: "purses", Popularity: 8})
if err != nil {
// handle error
}

Insert documents →

4. Query data

product, err := catalogs.ReadOne(ctx, filter.Eq("Brand", "adidas"))
if err != nil {
panic(err)
}
fmt.Println(product)

Query documents →

5. Search data

request := search.NewRequestBuilder().WithQuery("running").Build()
it, err := catalogs.Search(ctx, request)
if err != nil {
// handle error
}
defer it.Close()

var result search.Result[Catalog]
for it.Next(&result) {
fmt.Printf("%+v\n", result)
}
if it.Err() != nil {
// handle streaming error
}

Search documents →