keyvalue

package module
v0.1.28 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: CC0-1.0 Imports: 19 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Drivers

func Drivers() (names []string)

Drivers returns a sorted list of the names of the registered drivers.

func NewReader

func NewReader(r io.Reader, opts ReaderOptions) (record.Iterator, error)

NewReader returns a new "key: value" iterator for the given io.Reader.

func Register

func Register(name string, d driver.Driver)

Register makes a key-value driver available by the provided name. If Register is called twice with the same name or if driver is nil, it panics. A driver name must not contain the three character sequence "://".

Types

type Connection

type Connection struct {
	log.BasicLogable
	metrics.BasicMetricsable
	// contains filtered or unexported fields
}

Connection provides a database connection.

func Open

func Open(ctx context.Context, dataSource string) (*Connection, error)

Open opens a connection using the given data source.

func (*Connection) Close

func (c *Connection) Close() error

Close closes the connection to the database.

func (*Connection) ConnectToTable

func (c *Connection) ConnectToTable(ctx context.Context, name string) (*Table, error)

ConnectToTable connects to the indicated table in the database.

func (*Connection) CreateTable

func (c *Connection) CreateTable(ctx context.Context, 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 (*Connection) DataSource

func (c *Connection) DataSource() string

DataSource returns the data source string used to establish the connection. Note that this may contain sensitive user data such as a password.

func (*Connection) DeleteTable

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

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

func (*Connection) DriverName

func (c *Connection) DriverName() string

DriverName returns the name of the associated driver.

func (*Connection) ListTables

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

ListTables returns the names of the tables in the database. The names are sorted in increasing order.

func (*Connection) SetMetrics

func (c *Connection) SetMetrics(m metrics.Interface)

SetMetrics sets a metrics endpoint.

type ReaderError

type ReaderError interface {
	Error() string // Error returns a string representation of the error.
	Line() uint64  // Line returns the line number on which the error occurred.
	Index() uint64 // Index returns the record index for which the error occurred (indexed from 1).
	Key() string   // Key returns the key associated with this error, if known.
}

ReaderError is the interface satisfied by some errors returned by a "key: value" parser.

type ReaderOptions

type ReaderOptions struct {
	Template           record.Record // Specifies the value types.
	AllowDuplicateKeys bool          // If true, duplicate keys are allowed, with only the most recently read value appearing in the read record.
	AllowEmptyKeys     bool          // If true, allow the read record to have empty keys.
	AllowMissingKeys   bool          // If true, allow read records not to have all the keys in Template; that is, there may be keys in Template that are missing from the read record.
	AllowUnknownKeys   bool          // If true, allow read records to have keys not in Template; that is, there may be keys in the read record that are missing from Template. The type of the associated value will be a string. Note that if IgnoreUnknownKeys is true then AllowUnknownKeys is ignored.
	IgnoreUnknownKeys  bool          // If true, ignore any keys not in Template; that is, any keys not in Template will be skipped and will be omitted from the read record. Note that IgnoreUnknownKeys takes priority over AllowUnknownKeys.
}

ReaderOptions specified options for a reader.

type Table

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

Table provides a database connection.

func (*Table) AddIndex

func (t *Table) AddIndex(ctx context.Context, 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 (*Table) AddUniqueIndex

func (t *Table) AddUniqueIndex(ctx context.Context, 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 (*Table) Close

func (t *Table) Close() error

Close closes the connection to the table.

func (*Table) Count

func (t *Table) Count(ctx context.Context, selector record.Record) (int64, error)

Count returns the number of records in the table that match "selector".

func (*Table) CountWhere

func (t *Table) CountWhere(ctx context.Context, cond condition.Condition) (int64, error)

CountWhere returns the number of records in the table that satisfy condition "cond" (which may be nil if there are no conditions).

func (*Table) Delete

func (t *Table) Delete(ctx context.Context, selector record.Record) (int64, error)

Delete deletes those records in the table that match "selector". Returns the number of records deleted.

func (*Table) DeleteIndex

func (t *Table) DeleteIndex(ctx context.Context, key string) error

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

func (*Table) DeleteWhere

func (t *Table) DeleteWhere(ctx context.Context, cond condition.Condition) (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.

func (*Table) Describe

func (t *Table) Describe(ctx context.Context) (record.Record, error)

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.

func (*Table) Insert

func (t *Table) Insert(ctx context.Context, itr record.Iterator) error

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

func (*Table) InsertRecords

func (t *Table) InsertRecords(ctx context.Context, records ...record.Record) error

InsertRecords inserts the given records into the table.

func (*Table) ListIndices

func (t *Table) ListIndices(ctx context.Context) ([]string, error)

ListIndices lists the keys for which indices are present.

func (*Table) Log

func (t *Table) Log() log.Interface

Log returns the log for this table.

func (*Table) Metrics

func (t *Table) Metrics() metrics.Interface

Metrics returns the metrics endpoint for this table.

func (*Table) Name

func (t *Table) Name() string

Name return the table name.

func (*Table) Select

func (t *Table) Select(ctx context.Context, template record.Record, selector record.Record, order sort.OrderBy) (record.Iterator, error)

Select returns the 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".

func (*Table) SelectLimit

func (t *Table) SelectLimit(ctx context.Context, template record.Record, selector record.Record, order sort.OrderBy, n int64) (record.Iterator, 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".

func (*Table) SelectOne

func (t *Table) SelectOne(ctx context.Context, template record.Record, selector record.Record, order sort.OrderBy) (record.Record, 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.

func (*Table) SelectOneWhere

func (t *Table) SelectOneWhere(ctx context.Context, template record.Record, cond condition.Condition, 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.

func (*Table) SelectWhere

func (t *Table) SelectWhere(ctx context.Context, 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 (*Table) SelectWhereLimit

func (t *Table) SelectWhereLimit(ctx context.Context, template record.Record, cond condition.Condition, order sort.OrderBy, n int64) (record.Iterator, 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".

func (*Table) Update

func (t *Table) Update(ctx context.Context, replacement record.Record, selector record.Record) (int64, 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.

func (*Table) UpdateWhere

func (t *Table) UpdateWhere(ctx context.Context, replacement record.Record, cond condition.Condition) (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.

Directories

Path Synopsis
cmd
kvdbdriver
Package kvdbdriver implements the kvdb keyvalue driver.
Package kvdbdriver implements the kvdb keyvalue driver.
Package mongodb implements the keyvalue interfaces when working with mongodb.
Package mongodb implements the keyvalue interfaces when working with mongodb.
Package parse defines a parser for parsing SQL-formatted queries.
Package parse defines a parser for parsing SQL-formatted queries.
Package postgres implements the keyvalue interfaces when working with PostgreSQL.
Package postgres implements the keyvalue interfaces when working with PostgreSQL.

Jump to

Keyboard shortcuts

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