driver

package
v1.0.0-alpha.8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: Apache-2.0 Imports: 21 Imported by: 9

Documentation

Index

Examples

Constants

View Source
const (
	GRPC = iota
	HTTP = iota

	TokenEnv = "TIGRIS_TOKEN"

	Version   = "v1.0.0"
	UserAgent = "tigris-client-go/" + Version
)
View Source
const (
	DefaultGRPCPort = 443
)
View Source
const (
	DefaultHTTPPort = 443
)

Variables

View Source
var (
	DefaultProtocol  = GRPC
	ToekenRefreshURL = "https://tigrisdata-dev.us.auth0.com/oauth/token"
)

Functions

func GRPCError

func GRPCError(err error) error

func HTTPError

func HTTPError(err error, resp *http.Response) error

Types

type CRUDTx

type CRUDTx interface {
	// Insert array of documents into specified database and collection.
	Insert(ctx context.Context, collection string, docs []Document, options ...*InsertOptions) (*InsertResponse, error)

	// Replace array of documents into specified database and collection
	// Creates document if it doesn't exist.
	Replace(ctx context.Context, collection string, docs []Document, options ...*ReplaceOptions) (*ReplaceResponse, error)

	// Read documents from the collection matching the specified filter.
	Read(ctx context.Context, collection string, filter Filter, fields Projection, options ...*ReadOptions) (Iterator, error)

	// Update documents in the collection matching the speficied filter.
	Update(ctx context.Context, collection string, filter Filter, fields Update, options ...*UpdateOptions) (*UpdateResponse, error)

	// Delete documents from the collection matching specified filter.
	Delete(ctx context.Context, collection string, filter Filter, options ...*DeleteOptions) (*DeleteResponse, error)

	// CreateOrUpdateCollection either creates a collection or update the collection with the new schema.
	CreateOrUpdateCollection(ctx context.Context, collection string, schema Schema, options ...*CollectionOptions) error

	// DropCollection deletes the collection and all documents it contains.
	DropCollection(ctx context.Context, collection string, options ...*CollectionOptions) error

	// ListCollections lists collections in the database.
	ListCollections(ctx context.Context, options ...*CollectionOptions) ([]string, error)
}

CRUDTx is the interface that encapsulates the CRUD portions of the transaction API.

type CollectionOptions

type CollectionOptions api.CollectionOptions

type Config

type Config struct {
	TLS   *tls.Config `json:"tls,omitempty"`
	Token string      `json:",omitempty"`
}

type DatabaseOptions

type DatabaseOptions api.DatabaseOptions

type DeleteOptions

type DeleteOptions api.DeleteRequestOptions

type DeleteResponse

type DeleteResponse api.DeleteResponse

type DescribeCollectionResponse

type DescribeCollectionResponse api.DescribeCollectionResponse

type DescribeDatabaseResponse

type DescribeDatabaseResponse api.DescribeDatabaseResponse

type Document

type Document json.RawMessage

type Driver

type Driver interface {
	// Insert array of documents into specified database and collection
	Insert(ctx context.Context, db string, collection string, docs []Document, options ...*InsertOptions) (*InsertResponse, error)
	// Replace array of documents into specified database and collection
	// Creates document if it doesn't exist
	Replace(ctx context.Context, db string, collection string, docs []Document, options ...*ReplaceOptions) (*ReplaceResponse, error)
	// Read documents matching specified filter in the specified database and collection
	Read(ctx context.Context, db string, collection string, filter Filter, fields Projection, options ...*ReadOptions) (Iterator, error)
	// Update documents matching specified filter, with provided fields projection
	Update(ctx context.Context, db string, collection string, filter Filter, fields Update, options ...*UpdateOptions) (*UpdateResponse, error)
	// Delete documents matching specified filter form the specified database and collection
	Delete(ctx context.Context, db string, collection string, filter Filter, options ...*DeleteOptions) (*DeleteResponse, error)
	// CreateOrUpdateCollection either creates a collection or update the collection with the new schema
	// There are three categories of data types supported:
	//   Primitive: Strings, Numbers, Binary Data, Booleans, UUIDs, DateTime
	//   Complex: Arrays
	//   Objects: A container data type defined by the user that stores fields of primitive types,
	//   complex types as well as other Objects
	//
	//  The data types are derived from the types defined in the JSON schema specification
	//  with extensions that enable support for richer semantics.
	//  As an example, the string is defined like this,
	//   {
	//     "name": {
	//       "type": "string"
	//     }
	//   }
	// More detailed information here: https://docs.tigrisdata.com/datamodels/types
	CreateOrUpdateCollection(ctx context.Context, db string, collection string, schema Schema, options ...*CollectionOptions) error
	// DropCollection deletes the collection and all documents it contains
	DropCollection(ctx context.Context, db string, collection string, options ...*CollectionOptions) error
	// CreateDatabase creates new database
	CreateDatabase(ctx context.Context, db string, options ...*DatabaseOptions) error
	// DropDatabase deletes the database and all collections it contains
	DropDatabase(ctx context.Context, db string, options ...*DatabaseOptions) error
	// ListCollections lists collections in the database
	ListCollections(ctx context.Context, db string, options ...*CollectionOptions) ([]string, error)
	// ListDatabases in the current namespace
	ListDatabases(ctx context.Context) ([]string, error)
	// DescribeCollection returns metadata of the collection in the database
	DescribeCollection(ctx context.Context, db string, collection string, options ...*CollectionOptions) (*DescribeCollectionResponse, error)
	// DescribeDatabase returns database metadata
	DescribeDatabase(ctx context.Context, db string) (*DescribeDatabaseResponse, error)
	// BeginTx starts new transaction
	BeginTx(ctx context.Context, db string, options ...*TxOptions) (Tx, error)
	// Close releases resources of the driver
	Close() error
}

Driver implements Tigris API

Example
ctx := context.TODO()

c, _ := NewDriver(ctx, "localhost", &Config{})

_ = c.CreateDatabase(ctx, "db1", &DatabaseOptions{})

_ = c.CreateOrUpdateCollection(ctx, "db1", "coll1",
	Schema(`{ "properties": { "F1": { "type": "string" }, "F2": { "type": "string" } }, "primary_key": ["F1"] }`))

_, _ = c.Insert(ctx, "db1", "c1", []Document{Document(`{"F1":"V1"}`)})

it, _ := c.Read(ctx, "db1", "c1", Filter(`{"F1":"V1"}`), Projection(`{}`))

var doc Document
for it.Next(&doc) {
	fmt.Printf("doc: %v\n", doc)
}

_ = it.Err()

_, _ = c.Delete(ctx, "db1", "c1", Filter(`{"F1":"V1"}`))

tx, _ := c.BeginTx(ctx, "db1", nil)
defer func() { _ = tx.Rollback(ctx) }()

_, _ = tx.Insert(ctx, "c1", []Document{Document(`{"F1":"V1"}`)})

it, _ = tx.Read(ctx, "c1", Filter(`{"F1":"V1"}`), Projection("{}"))

for it.Next(&doc) {
	fmt.Printf("doc: %v\n", doc)
}

_ = it.Err()

_, _ = tx.Update(ctx, "c1", Filter(`{"F1":"V1"}`),
	Update(`{"$set" : { "F2" : "V2"}}`), &UpdateOptions{})

_, _ = tx.Delete(ctx, "c1", Filter(`{"F1":"V1"}`), &DeleteOptions{})

_ = tx.Commit(ctx)

_ = c.DropDatabase(ctx, "db1", &DatabaseOptions{})
Output:

func NewDriver

func NewDriver(ctx context.Context, url string, config *Config) (Driver, error)

NewDriver connect to Tigris at the specified URL URL should be in the form: {hostname}:{port}

func NewGRPCClient

func NewGRPCClient(ctx context.Context, url string, config *Config) (Driver, error)

func NewHTTPClient

func NewHTTPClient(ctx context.Context, url string, config *Config) (Driver, error)

type Filter

type Filter json.RawMessage

type InsertOptions

type InsertOptions api.InsertRequestOptions

type InsertResponse

type InsertResponse api.InsertResponse

type Iterator

type Iterator interface {
	Next(d *Document) bool
	Err() error
}

type Projection

type Projection json.RawMessage

type ReadOptions

type ReadOptions api.ReadRequestOptions

type ReplaceOptions

type ReplaceOptions api.ReplaceRequestOptions

type ReplaceResponse

type ReplaceResponse api.ReplaceResponse

type Schema

type Schema json.RawMessage

type Tx

type Tx interface {
	// Commit all the modification of the transaction
	Commit(ctx context.Context) error

	// Rollback discard all the modification made by the transaction
	Rollback(ctx context.Context) error

	CRUDTx
}

Tx object is used to atomically modify documents. This object is returned by BeginTx

type TxOptions

type TxOptions api.TransactionOptions

type Update

type Update json.RawMessage

type UpdateOptions

type UpdateOptions api.UpdateRequestOptions

type UpdateResponse

type UpdateResponse api.UpdateResponse

type WriteOptions

type WriteOptions api.WriteOptions

Jump to

Keyboard shortcuts

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