keyvalue

package module
v0.2.16 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 21 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection interface {
	metrics.Metricsable
	log.Logable
	io.Closer
	// DriverName returns the name of the associated driver.
	DriverName() string
	// ListDatabases returns the names of the available databases. The names
	// are sorted in increasing order. This is not supported by every driver,
	// in which case errors.OperationNotSupported will be returned.
	ListDatabases(ctx context.Context) ([]string, error)
	// CreateDatabase creates a database with the given name on the
	// connection.
	CreateDatabase(ctx context.Context, name string) error
	// DeleteDatabase deletes the indicated database on the connection. Does
	// not return an error if the table does not exist.
	DeleteDatabase(ctx context.Context, name string) error
	// ConnectToDatabase connects to the indicated database.
	ConnectToDatabase(ctx context.Context, name string) (Database, error)
}

Connection provides a connection.

func NewConnection added in v0.1.37

func NewConnection(c driver.Connection) Connection

NewConnection returns a new connection wrapping the given driver connection.

type Database added in v0.1.37

type Database interface {
	metrics.Metricser
	log.Logger
	io.Closer
	// Name return the database name.
	Name() string
	// ListTables returns the names of the tables in the database. The names
	// are sorted in increasing order.
	ListTables(ctx context.Context) ([]string, 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).
	CreateTable(ctx context.Context, name string, template record.Record) error
	// DeleteTable deletes the indicated table from the database. Does not
	// return an error if the table does not exist.
	DeleteTable(ctx context.Context, name string) error
	// RenameTable changes the name of a table in the database.
	RenameTable(ctx context.Context, oldname string, newname string) error
	// ConnectToTable connects to the indicated table in the database.
	ConnectToTable(ctx context.Context, name string) (Table, error)
}

Database provides a connection to a database.

type Table

type Table interface {
	metrics.Metricser
	log.Logger
	io.Closer
	// Name return the table name.
	Name() string
	// Describe returns a best-guess template for the data in this 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.
	Describe(ctx context.Context) (record.Record, error)
	// Count returns the number of records in the table that match
	// "selector".
	Count(ctx context.Context, selector record.Record) (int64, error)
	// CountWhere returns the number of records in the table that satisfy
	// condition "cond" (which may be nil if there are no conditions).
	CountWhere(ctx context.Context, cond condition.Condition) (int64, error)
	// InsertRecords inserts the given records into the table.
	InsertRecords(ctx context.Context, records ...record.Record) error
	// Insert inserts the records in the given iterator into the table.
	Insert(ctx context.Context, itr iter.Seq[record.Record]) error
	// Update updates all records in the table that match "selector" by
	// setting all keys present in "replacement" to the given values.
	// Returns the number of records updated.
	Update(ctx context.Context, replacement record.Record, selector record.Record) (int64, error)
	// UpdateWhere updates all records in the table that satisfy condition
	// "cond" (which may be nil if there are no conditions) by setting all
	// keys present in "replacement" to the given values. Returns the number
	// of records updated.
	UpdateWhere(ctx context.Context, replacement record.Record, cond condition.Condition) (int64, error)
	// Select returns an iterator "itr" of records matching "selector",
	// 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". The iterator "itr" is bound to the given
	// context. Iteration will be terminated on error. Any error will be
	// reported by the returned "finished" function.
	//
	// It returns a single-use iterator.
	Select(ctx context.Context, template record.Record, selector record.Record, order sort.OrderBy) (itr iter.Seq[record.Record], finished func() error)
	// SelectWhere returns an iterator "itr" of 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". The iterator "itr" is bound to the given
	// context. Iteration will be terminated on error. Any error will be
	// reported by the returned "finished" function.
	//
	// It returns a single-use iterator.
	SelectWhere(ctx context.Context, template record.Record, cond condition.Condition, order sort.OrderBy) (itr iter.Seq[record.Record], finished func() error)
	// SelectLimit returns at most n records matching "selector", 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". The iterator "itr" is bound to the given context.
	// Iteration will be terminated on error. Any error will be reported
	// by the returned "finished" function.
	//
	// It returns a single-use iterator.
	SelectLimit(ctx context.Context, template record.Record, selector record.Record, order sort.OrderBy, n int64) (itr iter.Seq[record.Record], finished func() error)
	// SelectWhereLimit returns at most n 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". The iterator "itr" is bound to the given context.
	// Iteration will be terminated on error. Any error will be reported
	// by the returned "finished" function.
	//
	// It returns a single-use iterator.
	SelectWhereLimit(ctx context.Context, template record.Record, cond condition.Condition, order sort.OrderBy, n int64) (itr iter.Seq[record.Record], finished func() error)
	// SelectOne returns the first record matching "selector", sorted as
	// specified by "order" (which may be nil if there is no sort order
	// required). The returned record will be in the form specified by
	// "template". If no records match, then a nil record will be returned.
	SelectOne(ctx context.Context, template record.Record, selector record.Record, order sort.OrderBy) (record.Record, error)
	// SelectOneWhere returns the first record 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 record will be in the form specified by "template". If no
	// records match, then a nil record will be returned.
	SelectOneWhere(ctx context.Context, template record.Record, cond condition.Condition, order sort.OrderBy) (record.Record, error)
	// Delete deletes those records in the table that match "selector".
	// Returns the number of records deleted.
	Delete(ctx context.Context, selector record.Record) (int64, error)
	// DeleteWhere deletes those records in the table that satisfy condition
	// "cond" (which may be nil if there are no conditions). Returns the
	// number of records deleted.
	DeleteWhere(ctx context.Context, cond condition.Condition) (int64, error)
	// AddIndex adds an index on the given key. If an index already exists,
	// this index is unmodified and nil is returned.
	AddIndex(ctx context.Context, key string) error
	// DeleteIndex deletes the index on the given key. If no index is
	// present, nil is returned.
	DeleteIndex(ctx context.Context, key string) error
	// ListIndices lists the keys for which indices are present. The keys
	// are sorted in increasing order.
	ListIndices(ctx context.Context) ([]string, error)
	// AddKeys updates each record r 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.
	AddKeys(ctx context.Context, rec record.Record) error
	// AddKey updates each record r in the table, adding the given
	// key-value pair if key is not already present in r.
	AddKey(ctx context.Context, key string, value any) error
	// DeleteKeys updates each record in the table, deleting all the
	// specified keys if present.
	DeleteKeys(ctx context.Context, keys []string) error
	// DeleteKey updates each record in the table, deleting the specified
	// key if present.
	DeleteKey(ctx context.Context, key string) error
}

Table provides a database connection to a table.

Directories

Path Synopsis
cmd
pcas-kvdbd command
internal
Package parse defines a parser for parsing SQL-formatted queries.
Package parse defines a parser for parsing SQL-formatted queries.

Jump to

Keyboard shortcuts

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