kvdb

package
Version: v0.1.30 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2021 License: CC0-1.0, CC0-1.0 Imports: 32 Imported by: 4

Documentation

Index

Constants

View Source
const (
	DefaultTCPPort = 12356
	DefaultWSPort  = 80
)

The default ports that kvdb listens on.

View Source
const (
	DefaultMaxMessageSize  = 16 * 1024 * 1024 // 16Mb
	DefaultReadBufferSize  = 64 * 1024        // 64Kb
	DefaultWriteBufferSize = 64 * 1024        // 64Kb
)

The default kvdb server values.

Variables

View Source
var ErrNilConfiguration = errors.New("illegal nil configuration data")

ErrNilConfiguration is returned when a ClientConfig fails to validate.

Functions

This section is empty.

Types

type Client

type Client struct {
	log.BasicLogable
	// contains filtered or unexported fields
}

Client is the client-view of the server.

func NewClient

func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error)

NewClient returns a new client view of the server specified by the configuration cfg.

func (*Client) AddIndex

func (c *Client) AddIndex(ctx context.Context, dbName string, tableName string, key string) error

AddIndex adds an index on the given key. If an index already exists, this index is unmodified and nil is returned.

func (*Client) AddKeys added in v0.1.29

func (c *Client) AddKeys(ctx context.Context, dbName string, tableName string, rec record.Record) error

AddKeys updates each record r in the table, adding any keys in rec that are not already present along with the corresponding values. Any keys that are already present in r will be left unmodified.

func (*Client) AddUniqueIndex

func (c *Client) AddUniqueIndex(ctx context.Context, dbName string, tableName string, key string) error

AddUniqueIndex adds an index on the given key and the constraint that, for each value of this key, there is at most one record with that value. This operation may fail if there is an existing index on that key, and will fail if the existing values in the table do not satisfy the uniqueness constraint.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection.

func (*Client) CountWhere

func (c *Client) CountWhere(ctx context.Context, dbName string, tableName string, cond condition.Condition) (int64, error)

CountWhere returns the number of records in the table that satisfy the condition "cond".

func (*Client) CreateTable

func (c *Client) CreateTable(ctx context.Context, dbName string, name string, template record.Record) error

CreateTable creates a table with the given name in the database.

The provided template will be used by the underlying storage-engine to create the new table if appropriate; the storage-engine is free to ignore the template if it is not required (for example, in a schema-less database).

func (*Client) DeleteIndex

func (c *Client) DeleteIndex(ctx context.Context, dbName string, tableName string, key string) error

DeleteIndex deletes the index on the given key. If no index is present, nil is returned.

func (*Client) DeleteKeys added in v0.1.29

func (c *Client) DeleteKeys(ctx context.Context, dbName string, tableName string, keys []string) error

DeleteKeys updates all records in the table, deleting all the specified keys if present.

func (*Client) DeleteTable

func (c *Client) DeleteTable(ctx context.Context, dbName string, name string) error

DeleteTable deletes the indicated table from the database. Does not return an error if the table does not exist.

func (*Client) DeleteWhere

func (c *Client) DeleteWhere(ctx context.Context, dbName string, tableName string, cond condition.Condition) (int64, error)

DeleteWhere deletes those records in the table that satisfy the condition "cond". Returns the number of records deleted.

func (*Client) DescribeTable

func (c *Client) DescribeTable(ctx context.Context, dbName string, tableName string) (record.Record, error)

DescribeTable returns a best-guess template for the data in table.

Note that the accuracy of this template depends on the underlying storage engine. It might not be possible to return an exact description (for example, in a schema-less database), and in this case we return a good guess based on a sample of the data available.

func (*Client) Insert

func (c *Client) Insert(ctx context.Context, dbName string, tableName string, itr record.Iterator) (err error)

Insert inserts the records from the given iterator into the table.

func (*Client) InsertRecords

func (c *Client) InsertRecords(ctx context.Context, dbName string, tableName string, rs ...record.Record) (err error)

InsertRecords inserts the given records into the table.

func (*Client) ListIndices

func (c *Client) ListIndices(ctx context.Context, dbName string, tableName string) ([]string, error)

ListIndices lists the keys for which indices are present.

func (*Client) ListTables

func (c *Client) ListTables(ctx context.Context, dbName string) ([]string, error)

ListTables returns the names of the tables in the database.

func (*Client) RenameTable added in v0.1.29

func (c *Client) RenameTable(ctx context.Context, dbName string, oldname string, newname string) error

RenameTable changes the name of table src in the database to dst.

func (*Client) SelectWhere

func (c *Client) SelectWhere(ctx context.Context, dbName string, tableName string, template record.Record, cond condition.Condition, order sort.OrderBy) (record.Iterator, error)

SelectWhere returns the results satisfying condition "cond" (which may be nil if there are no conditions), sorted as specified by "order" (which may be nil if there is no sort order required). The returned records will be in the form specified by "template".

func (*Client) SelectWhereLimit

func (c *Client) SelectWhereLimit(ctx context.Context, dbName string, tableName string, template record.Record, cond condition.Condition, order sort.OrderBy, n int64) (record.Iterator, error)

SelectWhereLimit returns at most n results that satisfy the condition "cond" (which may be nil if there are no conditions), sorted as specified by "order" (which may be nil if there is no sort order required). The returned records will be in the form specified by "template".

func (*Client) UpdateWhere

func (c *Client) UpdateWhere(ctx context.Context, dbName string, tableName string, replacement record.Record, cond condition.Condition) (int64, error)

UpdateWhere updates all records in the table that satisfy the condition "cond" by setting the keys in "replacement" to the given values. Returns the number of records updated.

type ClientConfig

type ClientConfig struct {
	Address        *address.Address // The address to connect to
	SSLCert        []byte           // The SSL certificate (if any)
	AppName        string           // The application name to identify ourselves via
	MaxMessageSize int              // The maximum message size
}

ClientConfig describes the configuration options we allow a user to set on a client connection.

func DefaultConfig

func DefaultConfig() *ClientConfig

DefaultConfig returns a new client configuration initialised with the default values.

The initial default value for the host will be read from the environment variable

PCAS_KVDB_ADDRESS = "hostname[:port]" or "ws://host/path"

on package init.

func SetDefaultConfig

func SetDefaultConfig(c *ClientConfig) *ClientConfig

SetDefaultConfig sets the default client configuration to c and returns the old default configuration. This change will be reflected in future calls to DefaultConfig.

func (*ClientConfig) Copy

func (c *ClientConfig) Copy() *ClientConfig

Copy returns a copy of the configuration.

func (*ClientConfig) URI

func (c *ClientConfig) URI() string

URI returns the URI connection string.

Note that the returned string may differ slightly from the value returned c.Address.URI(). For example, if c.Address omits a port number, an appropriate default port number is used here.

func (*ClientConfig) URL

func (c *ClientConfig) URL(dbName string) string

URL returns a URL representation of the configuration, connecting to the given database.

func (*ClientConfig) Validate

func (c *ClientConfig) Validate() error

Validate validates the client configuration, returning an error if there's a problem.

type DatabaseDriverFunc

type DatabaseDriverFunc func(context.Context, string) (string, error)

DatabaseDriverFunc returns the driver name for the given database name.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option sets options on a kvdb server.

func AddHandler

func AddHandler(h handler.Interface) Option

AddHandler adds the given handler to the server.

func DatabaseDriver

func DatabaseDriver(f DatabaseDriverFunc) Option

DatabaseDriver sets the database driver function for the server.

func MaxMessageSize

func MaxMessageSize(size int) Option

MaxMessageSize sets the maximum message size (in bytes) the server can receive.

func ReadBufferSize

func ReadBufferSize(size int) Option

ReadBufferSize sets the size of the read buffer (in bytes).

func SSLCertAndKey

func SSLCertAndKey(crt []byte, key []byte) Option

SSLCertAndKey adds the given SSL public certificate and private key to the server.

func WriteBufferSize

func WriteBufferSize(size int) Option

WriteBufferSize sets the size of the write buffer (in bytes).

type Server

Server handles client communication.

func New

func New(options ...Option) (*Server, error)

New returns a new kvdb server.

Directories

Path Synopsis
Package kvdbdriver implements the kvdb keyvalue driver.
Package kvdbdriver implements the kvdb keyvalue driver.
internal

Jump to

Keyboard shortcuts

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