tigris-client-go

module
v1.0.0-alpha.32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2022 License: Apache-2.0

README

Tigris Go Client Library

Go Report Build Status Build Status codecov 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.

Documentation

Installation

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

Usage

package main

import (
	"context"
	"time"

	"github.com/tigrisdata/tigris-client-go/config"
	"github.com/tigrisdata/tigris-client-go/fields"
	"github.com/tigrisdata/tigris-client-go/filter"
	"github.com/tigrisdata/tigris-client-go/tigris"
)

type User struct {
	Id      int `tigris:"primary_key"`
	Name    string
	Balance float64
}

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
	defer cancel()
	
	// Connect to the Tigris server
	client, err := tigris.NewClient(ctx, &config.Database{Driver: config.Driver{URL: "localhost:8081"}})
	if err != nil {
		panic(err)
	}
	defer client.Close()

	// Create the database and collection if they don't exist,
	// otherwise update the schema of the collection if it already exists
	db, err := client.OpenDatabase(ctx, "hello_db", &User{})
	if err != nil {
		panic(err)
	}

	// Get the collection object, all the CRUD operations on the collection will be performed
	// through this collection object
	users := tigris.GetCollection[User](db)

	// Insert or replace user
	users.InsertOrReplace(ctx,
		&User{Id: 1, Name: "Jania McGrory", Balance: 6045.7},
		&User{Id: 2, Name: "Bunny Instone", Balance: 2948.87})

	// Read
	var user *User
	user, err = users.ReadOne(ctx, filter.Eq("Id", 1)) // find user with Id 1
	if err != nil {
		panic(err)
	}

	// Update - update user's name
	users.Update(ctx, filter.Eq("Id", 1), fields.Set("Name", "Jania McGrover"))

	// Delete - delete users with Id 1 or 2
	users.Delete(ctx, filter.Or(filter.Eq("Id", 1), filter.Eq("Id", 2)))
}

Developing

The following scripts will set up and install the dependencies needed for building and testing the client.

sh scripts/install_build_deps.sh
sh scripts/install_test_deps.sh

Once the dependencies have been installed, the tests can be run simply by

make test

License

This software is licensed under the Apache 2.0.

Directories

Path Synopsis
api
Package api contains code which is autogenerated from the OpenAPI and Protobuf API specifications
Package api contains code which is autogenerated from the OpenAPI and Protobuf API specifications
client/v1/api
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
server/v1
Package api is a reverse proxy.
Package api is a reverse proxy.
Package config contains configuration related structures and functions
Package config contains configuration related structures and functions
Package driver provides access to the low level Tigris API.
Package driver provides access to the low level Tigris API.
Package fields provides helpers to construct "field projections".
Package fields provides helpers to construct "field projections".
Package filter provides methods to build logical filters.
Package filter provides methods to build logical filters.
Package mock contains autogenerated, test related code.
Package mock contains autogenerated, test related code.
api
Package api is a generated GoMock package.
Package api is a generated GoMock package.
Package schema provides methods to build JSON schema of the collections from user defined models.
Package schema provides methods to build JSON schema of the collections from user defined models.
Package test contains testing helpers
Package test contains testing helpers
Package tigris provides an interface for accessing Tigris data-platform.
Package tigris provides an interface for accessing Tigris data-platform.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL