arangodb

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2022 License: MIT Imports: 9 Imported by: 0

README

go-arangodb

Package arangodb provides some missing bits that make working with github.com/arangodb/go-driver a bit more comfortable.

For tests, see the subpackage mocks for some generated mock code. There's also arangodb.NewDatabaseForTest which establishes a real Arango connection.

Documentation

Overview

Package arangodb provides some niceties for arangodb Go driver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCollection

func GetCollection(
	ctx context.Context,
	db driver.DatabaseCollections,
	name string,
	opt *driver.CreateCollectionOptions,
) (driver.Collection, error)

GetCollection returns the named collection and creates it if it doesn't exist yet. If opt is nil, default ones are used.

func NewArangoDatabase

func NewArangoDatabase(ctx context.Context, config ArangoConfig) (driver.Database, error)

NewArangoDatabase creates connection to arango database from configuration.

func NewDatabaseForTest

func NewDatabaseForTest(ctx context.Context, prefix ...string) (driver.Database, error)

NewDatabaseForTest creates a connection to ArangoDB suitable for Go tests.

For continuous integration, the variable STERN_CI_ARANGO_CONTAINER names a container used for the connection to the database. Authentication is disabled. If the variable is empty, 127.0.0.1 is used.

A new empty database is created with a random name prepended with PREFIX. If the prefix is empty, "gotest" is used.

Usage within unit tests is discouraged. The arangodb/mocks subpackage is better suited for that. NewDatabaseForTests still makes sense in functional tests though.

func Repsert

func Repsert(
	ctx context.Context,
	collection driver.Collection,
	entry interface{},
	mode ...OverwriteMode,
) (err error)

Repsert "replaces or inserts" entry into the collection.

By default, existing entry is completely replaced. This can be changed with optional mode parameter.

func RunInTransaction

func RunInTransaction(
	ctx context.Context,
	db driver.Database,
	cols driver.TransactionCollections,
	thunk func(context.Context) error,
) error

RunInTransaction encapsulates transaction handling.

Thunk is invoked in a transaction started with the given collections. Thunk must use the given context for database operations. Error returned by thunk is passed through to the callee.

func Upsert

func Upsert(ctx context.Context, col driver.Collection, sth interface{}, key string) error

Upsert either creates or updates a document in the given collection.

Types

type ArangoConfig

type ArangoConfig struct {
	Endpoints []string `yaml:"endpoints"`
	User      string   `yaml:"user"`
	Password  string   `yaml:"password"`
	Database  string   `yaml:"database"`
}

ArangoConfig provides connection details for an ArangoDB database.

type OverwriteMode

type OverwriteMode = driver.OverwriteMode

OverwriteMode tells how to overwrite a document in Repsert.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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