db

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBatchSize = 1000

DefaultBatchSize limits the maximum number of fetched items at a time. Such a limit is required to make network communication less loaded and escape gRPC message size limits.

Variables

View Source
var (
	// You are trying to get a next item from the finished iterator.
	ErrIterationFinished = errors.New("iteration finished")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

func Open

func Open(options ...Option) (conn *Connection, err error)

Open creates a new database connection. It takes a list of options to customize settings. See config_options.go for more details.

func (*Connection) Close

func (c *Connection) Close() error

Close closes internal connection with the server and cleans resources. It only returns nil in the current implementation.

The connection cannot be used after Close was called.

func (*Connection) GetIterator

func (c *Connection) GetIterator(ctx context.Context, options ...IterOption) (*Iterator, error)

GetIterator creates an iterator to iterate over values that satisfy the provided options.

See the iterator.go file to get list of available filters: - IterKeyEquals - IterFromVersion - IterSetLimit

func (*Connection) GetLatest

func (c *Connection) GetLatest(ctx context.Context, key string) (Triplet, error)

GetLast finds a triplet by key and returns the latest known from the perspective of the replica to which a connection has been established.

Triplets are sorted by version.

func (*Connection) Put

func (c *Connection) Put(ctx context.Context, key string, value string) (Triplet, error)

Put saves a new pair and returns the version of the inserted data in case of success.

type IterOption

type IterOption func(it *Iterator) error

IterOption configures an iterator. At the moment you can use only already written options.

func IterFromVersion

func IterFromVersion(version Version) IterOption

When IterFromVersion is provided, all yielded triplets have version greater than the given one.

By default there is no lower bound on allowed version.

func IterKeyEquals

func IterKeyEquals(key string) IterOption

When IterKeyEquals is provided, all yielded triplets have the given key.

By default triplets are not filtered by key.

func IterSetLimit

func IterSetLimit(limit *uint32) IterOption

When IterSetLimit is provided, the given value limits the number of triplets fetched at a time from a server.

By default the limit is set to DefaultBatchSize.

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

func (*Iterator) GetNext

func (i *Iterator) GetNext() (Triplet, error)

GetNext returns the next triplet if iteration is not finished.

func (*Iterator) HasNext

func (i *Iterator) HasNext() bool

HasNext checks if the iterator contains still not read elements.

type Option

type Option = func(cfg *Config)

func WithClient

func WithClient(client dbclient.Client) Option

WithClient takes an implementation of client that will be used to interact with a database server.

Default client is missed that means a new gRPC client will be created. If this option is provided, options which control gRPC connection are ignored.

func WithConnection

func WithConnection(conn *grpc.ClientConn) Option

WithConnection takes a gRPC connection that will be used to interact with a database server.

If this option is missed, a new connection will be created from the given server address. If this option is provided, WithServerAddress is ignored.

func WithDebugLogger

func WithDebugLogger() Option

WithDebugLogger configures logger to be verbose and human-friendly to simplify the debug.

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger takes a logger instance will be used to log database operations. You can change the encoding and the log level to customize output.

Default logger prints nothing.

func WithServerAddress

func WithServerAddress(address string) Option

WithServerAddress takes address of the server gRPC API.

The address is ignored if either a client or grpc connection are set by other options.

type Triplet

type Triplet struct {
	Key     string
	Value   string
	Version Version
}

Triplet represents a triplet from the database.

type Version

type Version struct {
	// contains filtered or unexported fields
}

Version represents a unique sequence number of a key-value pair.

The only recommended way to get Version is to fetch data. Inner implementation is hidden from user to provide compatibility of the external interface.

func NewVersion

func NewVersion(lseq string) Version

func (Version) String

func (v Version) String() string

Directories

Path Synopsis
kv package specifies the contract type used in ORM arguments and provides implementations of the contract for some popular types.
kv package specifies the contract type used in ORM arguments and provides implementations of the contract for some popular types.

Jump to

Keyboard shortcuts

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