buntdb

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2018 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Example
package main

import (
	"context"
	"log"

	buntdbtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/tidwall/buntdb"
	"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

func main() {
	db, err := buntdbtrace.Open(":memory:")
	if err != nil {
		log.Fatal(err)
	}

	// Create a root span, giving name, server and resource.
	_, ctx := tracer.StartSpanFromContext(context.Background(), "my-query",
		tracer.ServiceName("my-db"),
		tracer.ResourceName("initial-access"),
	)

	// use WithContext to associate the span with the parent
	db.WithContext(ctx).
		Update(func(tx *buntdbtrace.Tx) error {
			_, _, err := tx.Set("key", "value", nil)
			return err
		})

	db.View(func(tx *buntdbtrace.Tx) error {
		// you can also use WithContext on the transaction
		val, err := tx.WithContext(ctx).Get("key")
		log.Println(val)
		return err
	})
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	*buntdb.DB
	// contains filtered or unexported fields
}

A DB wraps a buntdb.DB, automatically tracing any transactions.

func Open

func Open(path string, opts ...Option) (*DB, error)

Open calls buntdb.Open and wraps the result.

func WrapDB

func WrapDB(db *buntdb.DB, opts ...Option) *DB

WrapDB wraps a buntdb.DB so it can be traced.

func (*DB) Begin

func (db *DB) Begin(writable bool) (*Tx, error)

Begin calls the underlying DB.Begin and traces the transaction.

func (*DB) Update

func (db *DB) Update(fn func(tx *Tx) error) error

Update calls the underlying DB.Update and traces the transaction.

func (*DB) View

func (db *DB) View(fn func(tx *Tx) error) error

View calls the underlying DB.View and traces the transaction.

func (*DB) WithContext

func (db *DB) WithContext(ctx context.Context) *DB

WithContext sets the context for the DB.

type Option

type Option func(cfg *config)

An Option customizes the config.

func WithContext

func WithContext(ctx context.Context) Option

WithContext sets the context for the transaction.

func WithServiceName

func WithServiceName(serviceName string) Option

WithServiceName sets the given service name for the transaction.

type Tx

type Tx struct {
	*buntdb.Tx
	// contains filtered or unexported fields
}

A Tx wraps a buntdb.Tx, automatically tracing any queries.

func WrapTx

func WrapTx(tx *buntdb.Tx, opts ...Option) *Tx

WrapTx wraps a buntdb.Tx so it can be traced.

func (*Tx) Ascend

func (tx *Tx) Ascend(index string, iterator func(key, value string) bool) error

Ascend calls the underlying Tx.Ascend and traces the query.

func (*Tx) AscendEqual

func (tx *Tx) AscendEqual(index, pivot string, iterator func(key, value string) bool) error

AscendEqual calls the underlying Tx.AscendEqual and traces the query.

func (*Tx) AscendGreaterOrEqual

func (tx *Tx) AscendGreaterOrEqual(index, pivot string, iterator func(key, value string) bool) error

AscendGreaterOrEqual calls the underlying Tx.AscendGreaterOrEqual and traces the query.

func (*Tx) AscendKeys

func (tx *Tx) AscendKeys(pattern string, iterator func(key, value string) bool) error

AscendKeys calls the underlying Tx.AscendKeys and traces the query.

func (*Tx) AscendLessThan

func (tx *Tx) AscendLessThan(index, pivot string, iterator func(key, value string) bool) error

AscendLessThan calls the underlying Tx.AscendLessThan and traces the query.

func (*Tx) AscendRange

func (tx *Tx) AscendRange(index, greaterOrEqual, lessThan string, iterator func(key, value string) bool) error

AscendRange calls the underlying Tx.AscendRange and traces the query.

func (*Tx) CreateIndex

func (tx *Tx) CreateIndex(name, pattern string, less ...func(a, b string) bool) error

CreateIndex calls the underlying Tx.CreateIndex and traces the query.

func (*Tx) CreateIndexOptions

func (tx *Tx) CreateIndexOptions(name, pattern string, opts *buntdb.IndexOptions, less ...func(a, b string) bool) error

CreateIndexOptions calls the underlying Tx.CreateIndexOptions and traces the query.

func (*Tx) CreateSpatialIndex

func (tx *Tx) CreateSpatialIndex(name, pattern string, rect func(item string) (min, max []float64)) error

CreateSpatialIndex calls the underlying Tx.CreateSpatialIndex and traces the query.

func (*Tx) CreateSpatialIndexOptions

func (tx *Tx) CreateSpatialIndexOptions(name, pattern string, opts *buntdb.IndexOptions, rect func(item string) (min, max []float64)) error

CreateSpatialIndexOptions calls the underlying Tx.CreateSpatialIndexOptions and traces the query.

func (*Tx) Delete

func (tx *Tx) Delete(key string) (val string, err error)

Delete calls the underlying Tx.Delete and traces the query.

func (*Tx) DeleteAll

func (tx *Tx) DeleteAll() error

DeleteAll calls the underlying Tx.DeleteAll and traces the query.

func (*Tx) Descend

func (tx *Tx) Descend(index string, iterator func(key, value string) bool) error

Descend calls the underlying Tx.Descend and traces the query.

func (*Tx) DescendEqual

func (tx *Tx) DescendEqual(index, pivot string, iterator func(key, value string) bool) error

DescendEqual calls the underlying Tx.DescendEqual and traces the query.

func (*Tx) DescendGreaterThan

func (tx *Tx) DescendGreaterThan(index, pivot string, iterator func(key, value string) bool) error

DescendGreaterThan calls the underlying Tx.DescendGreaterThan and traces the query.

func (*Tx) DescendKeys

func (tx *Tx) DescendKeys(pattern string, iterator func(key, value string) bool) error

DescendKeys calls the underlying Tx.DescendKeys and traces the query.

func (*Tx) DescendLessOrEqual

func (tx *Tx) DescendLessOrEqual(index, pivot string, iterator func(key, value string) bool) error

DescendLessOrEqual calls the underlying Tx.DescendLessOrEqual and traces the query.

func (*Tx) DescendRange

func (tx *Tx) DescendRange(index, lessOrEqual, greaterThan string, iterator func(key, value string) bool) error

DescendRange calls the underlying Tx.DescendRange and traces the query.

func (*Tx) DropIndex

func (tx *Tx) DropIndex(name string) error

DropIndex calls the underlying Tx.DropIndex and traces the query.

func (*Tx) Get

func (tx *Tx) Get(key string, ignoreExpired ...bool) (val string, err error)

Get calls the underlying Tx.Get and traces the query.

func (*Tx) Indexes

func (tx *Tx) Indexes() ([]string, error)

Indexes calls the underlying Tx.Indexes and traces the query.

func (*Tx) Intersects

func (tx *Tx) Intersects(index, bounds string, iterator func(key, value string) bool) error

Intersects calls the underlying Tx.Intersects and traces the query.

func (*Tx) Len

func (tx *Tx) Len() (int, error)

Len calls the underlying Tx.Len and traces the query.

func (*Tx) Nearby

func (tx *Tx) Nearby(index, bounds string, iterator func(key, value string, dist float64) bool) error

Nearby calls the underlying Tx.Nearby and traces the query.

func (*Tx) Set

func (tx *Tx) Set(key, value string, opts *buntdb.SetOptions) (previousValue string, replaced bool, err error)

Set calls the underlying Tx.Set and traces the query.

func (*Tx) TTL

func (tx *Tx) TTL(key string) (time.Duration, error)

TTL calls the underlying Tx.TTL and traces the query.

func (*Tx) WithContext

func (tx *Tx) WithContext(ctx context.Context) *Tx

WithContext sets the context for the Tx.

Jump to

Keyboard shortcuts

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