Documentation
¶
Overview ¶
Package arangodb provides some niceties for arangodb Go driver.
Index ¶
- func GetCollection(ctx context.Context, db driver.DatabaseCollections, name string, ...) (driver.Collection, error)
- func NewArangoDatabase(ctx context.Context, config ArangoConfig) (driver.Database, error)
- func NewDatabaseForTest(ctx context.Context, prefix ...string) (driver.Database, error)
- func Repsert(ctx context.Context, collection driver.Collection, entry interface{}, ...) (err error)
- func RunInTransaction(ctx context.Context, db driver.Database, cols driver.TransactionCollections, ...) error
- func Upsert(ctx context.Context, col driver.Collection, sth interface{}, key string) error
- type ArangoConfig
- type OverwriteMode
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 ¶
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.
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.